As occasionally happens, I have a very large number of Illustrator documents wherein I need to perform the same find and replace hundreds of times. My initial instinct was to batch action, but it wasnt working. Searches on here and google informed me that that course of action only really works in Illustrator 10, and is pretty broken in more recent versions (which are the only ones I have access to). I long for that check box in InDesigns find and replace featurethe search all open documents one...
So Ive turned to scripting, and I almost almost have it working:
=============
tell application "Adobe Illustrator"
set searchString to text returned of (display dialog "Find what?" default answer "")
set replaceString to text returned of (display dialog "Replace with?" default answer "")
set textArtItemCount to (count text frames in document 1)
if (textArtItemCount > 0) then
repeat with itemCounter from 1 to textArtItemCount
if (((contents of text frame itemCounter of document 1) as string) contains searchString) then
set contents of (words of text frame itemCounter of document 1 whose contents = searchString) to replaceString
end if
end repeat
end if
end tell
=============
So this works perfectly, as long as the initial variable searchString is always one word with no spaces.
This doesnt help me very much, because I need to search for multiple words at a time in order to do targeted formatting changes.
This script is modified version of the example script that appears on page 243 of the Applescript Scripting Reference PDFunder word. This is obviously the main problem, as word is defined as a string of text separated by whitespace and thus implies one word and one word only.
So how can I search for a multiple-word string?
Im very new to scripting for Adobe, and its taken a bit of wrapping my head around. If anyone can point me in the right direction, itd be much appreciated.