Script to replace fonts in all documents, including master pages + colour replacement
Hi,
Preface: I have a very rough understanding of javascript, so bear with me if my questions are very simple.
I have a bunch of documents I need to edit. For all of them, I know I need to change a font (with two different syles), and I need to do a colour replacement.
Here is some code I patched together:
for (var i = app.documents.length-1; i >= 0; i--) {
var doc = app.documents;
fontChange();
function fontChange(){
step1();
}
function step1(){
//Tuffy Regular > Roboto Regular
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Regular";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Regular";
app.activeDocument.pageItems.everyItem().locked = false;
app.activeDocument.stories.everyItem().changeText();
app.findChangeTextOptions.includeMasterPages = true;
}
fontChangeTwo();
function fontChangeTwo(){
step2();
}
function step2(){
//Tuffy Bold > Roboto Bold
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Bold";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Bold";
app.activeDocument.pageItems.everyItem().locked = false;
app.activeDocument.stories.everyItem().changeText();
app.findChangeTextOptions.includeMasterPages = true;
}
}
Problem 1) I thought the first two lines would allow me to run this in all my documents but it doesn't work.
Problem 2) For some reason, my InDesign refuses to recognise Roboto when I run the script. It replaces the font with "Roboto (otf)" and highlights the text in red. It works fine with other fonts. If I manually replace the text in red with "Roboto", it works fine.
I've had issues with Roboto for a while in InDesign, the only way I found to have it work is to NOT activate it on Adobe fonts and have it installed on my machine instead.
Problem 3) The easiest one, I don't know how to do a colour replacement. I need to replace Adobe's pure black with another colour from my palette.
I would be super grateful if anyone could help with any of these problems.
Thanks in advance.
