I have a script which iterates through the text in a story (in linked text frames). I would like InDesign to change the active page displayed so I can observe the action of the script as it goes through the text. However, the script below always returns “1” as the parent page (pName) of the text frame, and not the page where the script action is taking place. Is there a way to find out the “real” page where the script has selected text? I’ve used examples from Shirley Hopkins’ book. Here’s the relevant portion of my script below (the part that is commented out after “save” is where I was trying to figure this thing out):
repeat with j from 1 to x
set saveCounter to saveCounter + 1
if saveCounter > 25 then – save the document every 25th iteration
set saveCounter to 1
tell docRef
save
(* tell docRef
activate
set frameRef to my frameRefOfSelection()
set pName to name of parent page of frameRef
set active page of window 1 to page pName
zoom window 1 of docRef given fit page
end tell *)
end tell
end if
– do other stuff
end repeat
– HANDLERS
(Returns reference to active document; otherwise generates error.)
on getDocRef()
tell application “Adobe InDesign CC 2014”
if modal state = true then
error “Please close dialogs before running script”
end if
if not (exists document 1) then
error “Requires active document”
else
return document 1
end if
end tell
end getDocRef
(Returns reference to selected text frame or text frame of selected text. Throws error if no valid selection.)
on frameRefOfSelection()
set errStr to “Requires text or text frame selection.”
tell application “Adobe InDesign CC 2014”
set selList to selection
if length of selList > 0 then
if class of item 1 of selList is in {text, insertion point} then
set storyRef to parent of item 1 of selList
set frameRef to item 1 of text containers of storyRef
else if class of item 1 of selList = textFrame then
set frameRef to item 1 of selList
else
error errStr
end if
else
error errStr
end if
end tell
return frameRef
end frameRefOfSelection