Skip to content

Instantly share code, notes, and snippets.

@dvschultz
Created September 8, 2014 21:18
Show Gist options
  • Save dvschultz/bff8ea0996003124d1e1 to your computer and use it in GitHub Desktop.
Save dvschultz/bff8ea0996003124d1e1 to your computer and use it in GitHub Desktop.
run checkForUnusedStyles() and it will remove all unused styles in your documents
function checkForUnusedStyles() {
var currDoc = app.activeDocument;
var myParStyles = currDoc.paragraphStyles;
for (i = myParStyles.length-1; i >= 2; i-- ){
removeUnusedStyle('paragraph',myParStyles[i])
}
var myCharStyles = currDoc.characterStyles;
for (i = myCharStyles.length-1; i >= 2; i-- ){
removeUnusedStyle('character',myCharStyles[i])
}
}
function removeUnusedStyle(styleType,myStyle) {
//clear find change settings
app.findTextPreferences = null;
app.changeTextPreferences = null;
if (styleType == 'paragraph') {
app.findTextPreferences.appliedParagraphStyle = myStyle;
} else {
app.findTextPreferences.appliedCharacterStyle = myStyle;
}
var myFoundStyles = currDoc.findText();
if (myFoundStyles == 0) {
myStyle.remove();
}
//reset find change settings
app.findTextPreferences = null;
app.changeTextPreferences = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment