I have a working find script, which I use do pull an itemcode from documents - not to actually replace any text!
select every text frame of the page vpagelength of active document
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" -- search function
the only time this is an issue if the InDesign user has previously used the find/replace feature. In that case, the ‘replace with’ text carries forward, and the above script actually replaces the text, with that old legacy text.
Does anyone know how to blow out the old text in the ‘replace’ field so this does not happen?
by adding in a ‘dummy’ find-and-replace tell statement ahead of the actual find, it clears out the old settings:
on itemcode()
tell application "Adobe InDesign CS2" -- search function
tell active document
set a to page items of page vpagelength whose class is group
repeat with i in a
ungroup i
end repeat
end tell
select every text frame of the page vpagelength of active document
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" replacing with ""
tell active document
undo
end tell
select every text frame of the page vpagelength of active document
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" -- search function
end tell
end itemcode
Your method does not fully clear out all the legacy search settings. Search followed by “undo” is also a bit inefficient. These statements should precede and succeed your search command:
set find text preferences to nothing
set change text preferences to nothing
that is indeed much more elegant. however, when I try:
tell application "Adobe InDesign CS2"
tell application text preferences
set find text preferences to ""
set change text preferences to nothing
end tell
end tell
i get the error: A application constant or consideration can’t go after this property.
highlighting ‘find text preferences’
it doesn’t seem to matter whether i address the application, the preferences or document 1
You’ve changed the object of the command. The search is directed to the active document, which you originally had correct - you just needed to enclose it with the value-clearing statements.
set find text preferences to nothing
set change text preferences to nothing
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" -- search function
set find text preferences to nothing
set change text preferences to nothing
It would probably help if I tested my own work. I must’ve been looking at something crosseyed and picked up a word that didn’t belong. Strike “text” from my statements. It should read:
tell application "Adobe InDesign CS2"
set find preferences to nothing
set change preferences to nothing
tell active document to search for "whatever"
set find preferences to nothing
set change preferences to nothing
end