Created
September 8, 2014 21:18
-
-
Save dvschultz/bff8ea0996003124d1e1 to your computer and use it in GitHub Desktop.
run checkForUnusedStyles() and it will remove all unused styles in your documents
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
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