I’m trying to find text on each page and replace it with a jobNum and page number. The below text replaces all the text boxes in a spread rather than just the text on its page.
set JobNum to "1234"
tell application "Adobe InDesign CS5"
--Clear the find/change preferences.
set find text preferences to nothing
set change text preferences to nothing
--Search the document for the string "lot".
set find what of find text preferences to "XXXXXX"
--Set the find options.
set case sensitive of find change text options to false
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to false
set include locked stories for find of find change text options to false
set include master pages of find change text options to false
set whole word of find change text options to false
set myDoc to active document
set pageCounter to 1
set pageNumber to name of every page of myDoc
set lastItem to item -1 of pageNumber
set firstItem to item 1 of pageNumber
repeat with i from firstItem to lastItem
if i is less than "10" then
set fixNumber to "00" & i
set myFoundItems to find text
repeat with foundItem in myFoundItems
set contents of object reference of foundItem to JobNum & "__" & fixNumber
end repeat
else
if i is greater than "10" then
set fixNumber to "00" & i
set myFoundItems to find text
repeat with foundItem in myFoundItems
set contents of object reference of foundItem to JobNum & "__" & fixNumber
end repeat
end if
end if
end repeat
end tell
Hi. An undirected find text returns document-wide values. If you want to search somewhere else or specific, direct the find to that particular object. I don’t have access to anything later than CS, at the moment, but one of these lines should work:
you need to access the text frame you want by using tell text frame 1 or tell text frame 2 etc of what ever page it
is you need to be on, something like this would do the trick.
tell application "Adobe InDesign CS5.5"
set myDoc to active document
set find text preferences to nothing
set change text preferences to nothing
set _Changedtext to "CHANGED" as string
set find what of find text preferences to "XXXXXX"
set change to of change text preferences to _Changedtext
tell page 2 of myDoc
tell text frame 1
change text
end tell
end tell
end tell
Awesome thank you so much now I need to work out how to get the number of text frames that have the find text and repeat it.
set JobNum to "1234"
tell application "Adobe InDesign CS5"
set myDoc to active document
set find text preferences to nothing
set change text preferences to nothing
--set pageCounter to 1
set pageNumber to name of every page of myDoc
set lastItem to item -1 of pageNumber
set firstItem to item 1 of pageNumber
repeat with i from firstItem to lastItem
if i is less than "10" then
set fixNumber to "0" & i
set _Changedtext to JobNum & fixNumber as string
set find what of find text preferences to "XXXXXX"
set change to of change text preferences to _Changedtext
set theFrames to 1
tell page i of myDoc
tell text frame theFrames
change text
set theFrames to theFrames + 1
end tell
end tell
else
if i is greater than "10" then
--this if need updating
set myFoundItems to find text
repeat with foundItem in myFoundItems
set contents of object reference of foundItem to JobNum & "__" & i
end repeat
end if
end if
end repeat
end tell
The text frames can all be addressed, at once. If you need a specific count, “find text” produces that.
tell application "Adobe InDesign CS5.5"
tell document 1's page 1's text frames to find text (change text) -->find text's reference list
count (result's items)
end
Your phrasing can be affected by the numbering system used. Page 1 is an absolute reference to the first page. Page “1” references a page called 1 in section numbering.
No. Your page “2” is page 1. To clarify, regardless of auto page numbering, you are dealing with a position (index), when you specify a number, and dealing with a name, when specifying a string. You may need to adjust your code to suit, just be aware of the difference.
tell application "InDesign CS"'s document 1 to tell page 1 to name --might be "2" or "3" (or whatever)
tell application "InDesign CS"'s document 1 to tell page 1 to it --always 1