Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joonaspaakko/619f3c4d4e2acfb0f2518906c107ffb4 to your computer and use it in GitHub Desktop.
Save joonaspaakko/619f3c4d4e2acfb0f2518906c107ffb4 to your computer and use it in GitHub Desktop.
Indesign script
// Set true to "normalize" the character styled text = no extra leading & trailing spaces
var removeSpace = false;
app.findTextPreferences = null;
app.changeTextPreferences = null;
var findPref = app.findTextPreferences;
var changePref = app.changeTextPreferences;
findPref.appliedCharacterStyle = 'yellow-background';
var doc = app.activeDocument;
var search = doc.findText();
for (var i = 0; i < search.length; i++) {
var text = search[i];
var string = text.contents;
var space = removeSpace ? '' : ' '; // Just a regular space
changePref.changeTo = space + text.contents.replace(/^\s+/,'').replace(/\s+$/,'') + space;
text.changeText();
}
@joonaspaakko
Copy link
Author

Example gif:

color-bg-character-style-padding-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment