I had a script which worked with InDesign CS. It was designed to replace a text string with the path to a graphic file (so that the graphic remained inline in the text).
The relevant code was:
tell application "Adobe InDesign CS"
tell InDesignDocRef
select (search for ReplacementString)
tell selection of InDesignDocRef
place graphicFilePathString
end tell
end tell
end tell
InDesign CS 3 no longer likes the “select (search for …” construction. Any idea on what might replace it?
Thanks for the reply. I skimmed and searched the document you reference before I posted but it didn’t help. Can you point me to the relevant part for my problem?
On page 76 there is a sample script to find and replace text.
Probably you don’t need to set all find change text options
tell application "Adobe InDesign CS3"
--Clear the find/change preferences.
set find text preferences to nothing
set change text preferences to nothing
--Search the document for the string ReplacementString
set find what of find text preferences to ReplacementString
set change to of change text preferences to graphicFilePathString
--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
tell document 1
set myFoundItems to change text
display dialog ("Found " & (count myFoundItems) & " instances of the
search string.")
end tell
end tell
Thank you very much! That does solve half the problem. Unfortunately, it now replaces the string with the graphicFilePathString (like “Macintosh HD:Logo:Signature.jpg”) rather than placing the graphic at the appropriate place. The old code selected the found text and then used the place command to replace it with the graphic.
The graphic has to appear inline in the text at the location marked by the ReplacementString
I tried altering the code you quoted in a variety of ways. Where I’m stuck is at the point where you’d previously have written “place graphicFilePathString”. Any thoughts on how to accomplish that?
tell application "Adobe InDesign CS3"
--Clear the find/change preferences.
set find text preferences to nothing
--Search the document for the string ReplacementString
set find what of find text preferences to ReplacementString
tell document 1
set myFoundItems to find text
repeat with i in myFoundItems
set selection to i
tell selection
place graphicFilePathString
end tell
end repeat
end tell
end tell
That worked perfectly. I particularly liked the little extra craftsmanship of iterating through the found list. So the trick is creating a list using the “find text” command and then setting the selection to each of the found items of the search.
It always surprises me how difficult it is to learn the individual idiosyncracies of each program that one wishes to control with AppleScript and, in this case, the differences that each new rev brings. I feel fine with the core language but I must have missed the trick of how to properly read an application dictionary.
I totally agree.
My procedural method is first to read the dictionary (sadly they are often confusing)
and, if available, a guide like the Adobe one.
Then I search google to find sample scripts or useful informations
Finally I “try and error” the code
These normally work, but I’ve got a recurring problem with a particular string that refuses to be counted.
Other strings work successfully at being found/replaced. I’m using Shirley Hopkins’ handler for the find/replace. But this one bugger is throwing me. It fails even if I swap out the found text to something else.
Based on this thread, I’ve stripped down the code for ease of reading.
tell application "Adobe InDesign CS3"
set theDoc to document 1
set find text preferences to nothing
set change text preferences to nothing
set findText to "<SS>"
set changeText to "remit code"
set whole word of find change text options to false
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set find what of find text preferences to findText
set change to of change text preferences to changeText
tell theDoc
--tell page 1
set findText to changeText
display dialog ("Found " & (count findText) & " instances of the search string.")
--end tell --page 1
end tell --theDoc
end tell --app
The result of this script is that it finds 10 items. Even in a brand new document, with only the string in it.
Doing a find/change manually only finds the one instance which is correct.
So something about this string or text box is making it fail.
One possible clue is that this is adapted from my Quark script and it failed when my find text is “CODE”, but not when it was changed to “”.
What should I be looking for? thanx, sam
Browser: Safari 523.12
Operating System: Mac OS X (10.4)
This should probably be in a new thread, as it has little bearing on the original post from 6 month ago. There are 2 problems with your code. The first is that you are not actually initiating a search ““ just setting up the parameters for one ““ so there are no results to count. The second problem is with this line:
display dialog ("Found " & (count findText) & " instances of the search string.")
You are actually counting the text string “remit code”, which is 10 characters long.
Thank you for replying. You’re right it may be appropriate for a new topic, but the context of why I’m asking is here, as it is where I started.
And I can see the two mistakes I’m making. But how to apply the change? You see, early in this thread it’s referring to the ID CS3 Applescript document.
It’s telling me to “see the complete script, see ChangeText”. I’ve searched the pdf for that phrase and it seems to be in a loop. So not finding the example explained, I offered up my wounded duck.
How would one change the text (removing the useless dialog) thanx, sam