I am a noob in scripting and for a couple of days now, I have tried finding a script that will find a word in an Indesign CS2 doc and will replace it with another word AND apply a certain paragraph style to it.
For example:
Find “@txt” and replace it with “” and apply paragraph style “TXT”
If anyone could help me out, it would be very appreciated…
This is possible. You can thank Ray Robertson of Scripting Matters for this example. I attended his seminar in New York last week. The script below is almost an exact copy of his example script last week.
tell application "Adobe InDesign CS2"
(*it is best to make sure the find and change attributes are cleared before doing a new find.
Note that this must be addressed to the application, instead of the document, since this is an application preference.*)
set find preferences to nothing
set change preferences to nothing
--address the document to search all text
tell document 1
--change all occurences of the text to bold
search for "@txt" replacing with "CYOA" with change attributes {font style:"Bold"}
end tell
tell page 1 of document 1
set applied paragraph style of paragraph 1 of text frame 1 to "TXT"
end tell
end tell
Thanks drossi. It is not exactly what I am looking for though…
Here is what I’ve come up with so far:
tell application "Adobe InDesign CS2"
activate
set find preferences to nothing
set change preferences to nothing
tell document 1
set changeStyle1 to paragraph style "TK"
try
tell text frame 1
set myParas1 to (object reference of paragraphs whose contents begins with "@tk")
repeat with i from (count of myParas1) to 1 by -1
set applied paragraph style of (item i of myParas1) to changeStyle1
end repeat
end tell
end try
try
tell text frame 1
search for "@tk" replacing with "" without case sensitive and whole word
search for " = " replacing with "" without case sensitive and whole word
end tell
end try
end tell
end tell
Does anyone know though, how I can apply a paragraph style to paragraphs containing “@tk” for example?
Thanks.