Last active
August 29, 2015 14:07
-
-
Save grefel/55afd90a8e6a5ccd1a7b to your computer and use it in GitHub Desktop.
Get #InDesign Style by String
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 root = app.activeDocument; | |
var result = getStyleByString(root, "Formatgruppe 2:Form\\:atgruppe 1:Zeichen\\:\\:format 1", "characterStyles", true); | |
$.writeln(result.name); | |
function getStyleByString(root, string, property, recreate) { | |
if (recreate == undefined) recreate = false; | |
stringResult = string.match (/^(.*?[^\\]):(.*)$/); | |
var cStyleName = (stringResult) ? stringResult[1] : string; | |
cStyleName = cStyleName.replace(/\\:/g, ":"); | |
remainingString = (stringResult) ? stringResult[2] : ""; | |
var newProperty = (stringResult) ? property.replace(/s$/, '') + "Groups" : property; | |
var cStyle = root[newProperty].itemByName(cStyleName); | |
if (!cStyle.isValid && recreate) cStyle = root[newProperty].add({name:cStyleName}); | |
if (remainingString.length > 0 && cStyle.isValid) cStyle = getStyleByString (cStyle, remainingString, property, recreate); | |
return cStyle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment