Skip to content

Instantly share code, notes, and snippets.

@kmplngj
Forked from grefel/gist:55afd90a8e6a5ccd1a7b
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmplngj/2f5a447d92f4f761f0ab to your computer and use it in GitHub Desktop.
Save kmplngj/2f5a447d92f4f761f0ab to your computer and use it in GitHub Desktop.
var root = app.activeDocument;
var result = getStyleByString(root, "Formatgruppe 2:Form\\:atgruppe 1:Zeichen\\:\\:format 1", "characterStyles");
$.bp();
function getStyleByString(root, string, property) {
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 (remainingString.length > 0 && cStyle.isValid) cStyle = getStyleByString (cStyle, remainingString, property);
return cStyle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment