Skip to main content
Inspiring
October 20, 2023
Answered

Find and replace text by condition

  • October 20, 2023
  • 1 reply
  • 1048 views

Hi all! Can I have a script that finds text with "Condition 1" applied and replaces it with the text from "Condition 2"? I guess it should be a simple copy-paste?

 

I have already created and applied the conditions in the document. No need any fancy options or dialog boxe.


Thanks in advance for the help!

 

Regards,

Rogerio

This topic has been closed for replies.
Correct answer Anantha Prabu G

Hi,

 

Use the Folder object:

var fold = Folder(“some/path”);
var inddFiles =fold.getFiles(“*.indd”);
for (var i = 0; i < inddFiles.length; i++) {
var doc = app.open(inddFiles[i]);
//do stuff
}

1 reply

Inspiring
October 20, 2023

Just to clarify, there's a way to create and apply conditions to a text in InDesign via Conditional Text panel. It works like Layers, but for the text inside the frames instead - the condition marks up (by underlining or highlighting) the selected text and you can easily hide it from the document. It's very useful!

 

If we have a script for an appliedCharacterStyle, we can change it to  "appliedConditions" and I believe it should do the trick 🙂

Willi Adelberger
Community Expert
Community Expert
October 20, 2023

You can always apply a character style to text with a condition manuallxy. Problem is only, if a text has 2 conditions. In such a case you need to create a 3rd character style which represents 2 applied conditions,

Inspiring
October 20, 2023

Thanks for checking @Willi Adelberger! In this case, each text has only 1 condition applied. Basicaly, the script needs to copy the text with "Condition 2" applied and pasted it over (overwrite) the text in the "Condition 1".