Many thanks! This will be good practise 🙂
When trying to sort this out I also asked ChatGPT, who, after a number of iterations, wrote this script.
Cleaning up this doc takes so much longer than I had hoped. I now have to manually map each and every one of the 25 chapter files I have (I am seriuosly considering skipping the grouping of the styles in InDesign - all style names should by now be identical in the 25 word files (as they are all part of the same master document and using the same template.). I would have loved it if there was a setting at the InDesign import asking it to automatically map with styles of the identical name, ignoring if it is in a group (if there are multiple styles with identical names, in different groups, InDesign could ask me which one to pick in a pop.up)).
🙂
Anyway, I am learning loads and think that the end document will look very neat.
Again, many thanks!
(here is the ChatGPT script:
function deleteUnusedStyles(doc) {
// Activate the document
app.activeDocument = doc;
// Delete unused Paragraph Styles in all Open Documents
try {
app.menuActions.itemByID(8614).invoke(); // Select All Unused in Paragraph Styles
app.menuActions.itemByID(8536).invoke(); // Delete Selected Styles in Paragraph Styles
} catch (e) {
$.writeln("Error removing unused Paragraph Styles: " + e);
}
// Delete unused Character Styles
try {
app.menuActions.itemByID(8609).invoke(); // Select All Unused in Character Styles
app.menuActions.itemByID(8536).invoke(); // Delete Selected Styles in Character Styles
} catch (e) {
$.writeln("Error removing unused Character Styles: " + e);
}
// Delete unused Object Styles
try {
app.menuActions.itemByID(8619).invoke(); // Select All Unused in Object Styles
app.menuActions.itemByID(8536).invoke(); // Delete Selected Styles in Object Styles
} catch (e) {
$.writeln("Error removing unused Object Styles: " + e);
}
}
function main() {
var docs = app.documents;
for (var i = 0; i < docs.length; i++) {
deleteUnusedStyles(docs[i]);
}
}
// Run the script
main();
)
Almost - ChatGPT still doesn't have all the human experience.
You should change the order - CharStyle can be used in ParaStyle - so won't be "unused" if you don't remove ParaStyle first - and the same goes for ObjectStyles that can use ParaStyles.
So ObjectStyles 1st, then ParaStyles, then CharStyles.
Then there is a case of Table and Cell Styles - unless you don't have any in your documents.