I’m wanting to step through a text document (a Table of Contents), and update page numbers after having inserted some pages. After writing the first bit of code and never getting the expected result, I wrote the uncommented second script to check if and when an integer was encountered… it never was; every number in my list became a text. Can someone here see what I am missing and give me a hint? Thanks.
This is a snippet of the text I’m evaluating in my text editor:
Part 1: Welcome to NameofSoftware
Learning About NameofSoftware 6
Connecting to NameofSoftware from a remote machine 7
Part 2: Section Headline
etc.
(*
tell application "TextWrangler"
tell text window 1
repeat with wordX from 1 to count words
set theData to word wordX
if class of theData = integer then
set word wordX to (word wordX) + 5 --advance all numbers by inserted page count
end if
end repeat
end tell
end tell
*)
property theList : {}
tell application "TextWrangler"
tell text window 1
repeat with wordX from 1 to count words
set the end of theList to word wordX
end repeat
tell me to TestforIntegers()
end tell
end tell
to TestforIntegers()
repeat with listVar from 8 to 10 -- I shortened the range for this test. Item 9, which is "6", should be a number.
if class of item listVar in theList = integer then
display dialog "Bingo!" & return & "Item " & item listVar of theList & " is a winner."
else
display dialog "Item " & listVar & ", " & return & "''" & item listVar of theList & "''" & return & " is not an integer."
end if
end repeat
end TestforIntegers