Hi @ed_ben_c , You might want to search for italics and apply a character style—something like this (change Minion Pro Italic to your font):
//active document
var doc = app.activeDocument;
//create styles—-makeStyle checks if the style already exists
var ital = makeStyle(doc, "Italic", "characterStyles")
var ifnt = "Minion Pro Italic"
ital.appliedFont = ifnt
var bodyCopy = makeStyle(doc, "0 BODY TEXT", "paragraphStyles")
var catchlineCopy = makeStyle(doc, "1 CATCH LINE", "paragraphStyles")
var headlineCopy = makeStyle(doc, "2 Col sec HEADING", "paragraphStyles")
var introCopy = makeStyle(doc, "3 Body text INTRO", "paragraphStyles")
var quoteIntroCopy = makeStyle(doc, "4 Body intro QUOTES", "paragraphStyles")
var selection = doc.selection;
//NOTE doesn’t always work
if (!selection || selection.length === 0) {
alert("No text box is currently selected.");
}
var textBox = selection[0];
//gets any words set as Minion Pro Italic and applys the ital character style
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.appliedFont = ifnt;
var res = app.activeDocument.findText()
for (var i = 0; i < res.length; i++){
res[i].appliedCharacterStyle = ital
};
//apply paragraph styles to the first 3 paragraphs
selection[0].paragraphs.everyItem().properties = {appliedParagraphStyle: bodyCopy}
textBox.paragraphs.item(0).appliedParagraphStyle = catchlineCopy;
textBox.paragraphs.item(1).appliedParagraphStyle = headlineCopy;
if (textBox.paragraphs.item(2).contents.charAt(0) === '“') {
textBox.paragraphs.item(2).appliedParagraphStyle = quoteIntroCopy;
}
else {
textBox.paragraphs.item(2).appliedParagraphStyle = introCopy;
}
/**
* Make a new collection https://community.adobe.com/t5/indesign-discussions/how-to-create-various-styles-with-scripts/m-p/15344854#M626385
* @ param the document
* @ param the collection name string
* @ param the collection class as a string
* @ return the named collection
*/
function makeStyle(d, n, c) {
if (d[c].itemByName(n).isValid) {
return d[c].itemByName(n);
} else {
return d[c].add({name:n})
}
}
... View more