Last active
December 13, 2023 18:37
-
-
Save Gix075/3ebbc7915d2ef5614742a41c51753c1e to your computer and use it in GitHub Desktop.
InDesign Javascript code to apply a character style to all texts that match search criteria | InDesign script per assegnare uno stile di carattere a tutti i testi che corrispondono ai criteri di ricerca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var search_options = { | |
"styleName": "EtichettaLateraleCitta", // required (Il nome dello stile di carattere da applicare) | |
"fontName": "Poppins", // optional (Il nome del font da cercare) | |
"fontStyle": "Bold", // optional (Il nome dello stile del font da cercare) | |
"fontSize": 12, // optional (La dimensione del font da cercare) | |
"fontColor": "ColoreEuropa", // optional (Il nome del colore del font da cercare) | |
"searcgString": "", // optional (La stringa da cercare) | |
"ignoreCurrentStyle": false // optional (Se true, ignora lo stile di carattere corrente) | |
} | |
applyCharacterStyleToText( | |
search_options.styleName, | |
search_options.fontName, | |
search_options.fontStyle, | |
search_options.fontSize, | |
search_options.fontColor, | |
search_options.searcgString, | |
search_options.ignoreCurrentStyle | |
); | |
/** | |
* | |
* @param {string} styleName_toApply Required | |
* @param {string} fontStyle_toSearch | |
* @param {string} fontColor_toSearch | |
* @param {number} fontSize_toSearch | |
* @param {string} fontName_toSearch | |
* @param {string} string_toSearch | |
* @param {bool} ignoreCurrentStyle | |
* | |
*/ | |
function applyCharacterStyleToText(styleName_toApply, fontName_toSearch, fontStyle_toSearch, fontSize_toSearch, fontColor_toSearch, string_toSearch, ignoreCurrentStyle ) { | |
if (app.documents.length == 0) { | |
alert("Nessun documento aperto!"); | |
return; | |
} | |
var doc = app.activeDocument; | |
if (!doc.characterStyles.itemByName(styleName_toApply).isValid) { | |
alert("Stile di carattere non trovato: " + styleName_toApply); | |
return; | |
} | |
app.findTextPreferences = app.changeTextPreferences = null; | |
if (string_toSearch !== "") { | |
app.findTextPreferences.findWhat = string_toSearch; | |
} | |
if (fontStyle_toSearch !== "") { | |
app.findTextPreferences.fontStyle = fontStyle_toSearch; | |
} | |
if (fontColor_toSearch !== "") { | |
app.findTextPreferences.fillColor = doc.swatches.itemByName(fontColor_toSearch); | |
} | |
if (fontSize_toSearch !== "") { | |
app.findTextPreferences.pointSize = fontSize_toSearch; | |
} | |
if (fontName_toSearch !== "") { | |
app.findTextPreferences.appliedFont = fontName_toSearch; | |
} | |
var foundTexts = doc.findText(); | |
for (var i = 0; i < foundTexts.length; i++) { | |
if (ignoreCurrentStyle || foundTexts[i].appliedCharacterStyle.name == "[Nessuno]") { | |
foundTexts[i].appliedCharacterStyle = doc.characterStyles.itemByName(styleName_toApply); | |
} | |
} | |
app.findTextPreferences = app.changeTextPreferences = null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes it doesn't mach color names