Here’s my new version, from bits and pieces of contributors and a bit of my own.
Detects what I wanted, returns it in a list with the word and the page.
I’ll have to dig in more if I want to have more interaction…
tell application "Adobe InDesign CS3"
set storynumber to count document 1 each story --number of stories in current document
set verif1 to {}
set theList to {}
set lineNumber to {}
repeat with m from 1 to storynumber
set end of lineNumber to count story m of document 1 each line --for every story, add "number of lines in story" to the list linenumber
end repeat
tell document 1
repeat with n from 1 to storynumber -- for every story in the document
tell story n -- talk to selected story
repeat with i from 1 to item n of lineNumber --for every line in the current story
if length of line i is greater than 1 then --check that line is not empty
tell line i
set lastword to last word
set verif0 to ((baseline of first character of last word) is not (baseline of last character of last word)) --if the baseline of the first character of the last word of the current line is different from the baseline of its last character the verif 0 is true
set verif1 to (characters of lastword contains "-") --if the last word of the current line contains a hyphen then verif1 becomes true
set verif2 to my checkcaps(lastword) -- verif2 will be true if the last word contains a capitalized letter
if ((verif0 and verif1) or (verif0 and verif2)) then
set selection of application "Adobe InDesign CS3" to last word
select (last word)
tell application "Adobe InDesign CS3"
set thePage to (parent of parent text frames of selection)
-- set active page of layout window 1 to thePage
-- tell layout window 1
-- set zoom percentage to 100
-- end tell
end tell
set end of theList to ({lastword, name of thePage})
--display dialog "Next"
end if
end tell
end if
end repeat
end tell
end repeat
end tell
return theList
end tell
to checkcaps(passedword)
local capitalized, capitalletters
set capitalized to false as boolean
set capitalletters to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ASCII character 131, ASCII character 174, ASCII character 128, ASCII character 129, ASCII character 130, ASCII character 132, ASCII character 133, ASCII character 134, ASCII character 203, ASCII character 204, ASCII character 205, ASCII character 206, ASCII character 229, ASCII character 230, ASCII character 231, ASCII character 232, ASCII character 233, ASCII character 234, ASCII character 235, ASCII character 236, ASCII character 237, ASCII character 238, ASCII character 239, ASCII character 241, ASCII character 242, ASCII character 243, ASCII character 244} as list
repeat with zz from 1 to length of passedword
considering case
if capitalized = false then
set capitalized to (item zz of characters of passedword is in capitalletters)
end if
end considering
end repeat
return capitalized
end checkcaps
Now I’ll clean the code and try to optimize it, as it is pretty slow.
Fabrice