Copy link to clipboard
Copied
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
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
}
Copy link to clipboard
Copied
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 🙂
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
Hi everyone, I have managed to code it myself, but somehow the script only works when I have a single document open. Is there any way to make it work with multiple files? Here's the code:
for (var d=0; d<app.documents.length; d++)
{
var doc = app.documents[d];
var conditions = app.documents[d].conditions.item("Condition 2").visible = true;
app.findTextPreferences = null;
app.findTextPreferences.appliedConditions = ["Condition 2"];
var found = doc.findText();
for(var i =0;i<found.length;i++)
{
try{
found[i].select();
}catch(e){}
}
app.findTextPreferences = null;
try {
app.selection[0].texts[0].select();
app.cut();
} catch (_)
{
}
app.findTextPreferences = null;
app.findTextPreferences.appliedConditions = ["Condition 1"];
var found = doc.findText();
for(var i =0;i<found.length;i++)
{
try{
found[i].select();
}catch(e){}
}
app.findTextPreferences = null;
try {
app.selection[0].texts[0].select(SelectionOptions.REPLACE_WITH);
app.paste();
} catch (_)
{
}
Copy link to clipboard
Copied
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
}