Script to run app.menuActions on all open documents
I need to run a couple menuActions on a batch of documents and I'm not sure if what I've done is correct or if maybe there's a more common way to do it. Here's my script:
for (var i = 0; app.documents.length > i; i++) {
sortByName();
app.activeDocument = app.documents[1]; //go to the next document
}
function sortByName() {
app.menuActions.itemByID(8505).invoke(); //sort p-styles
app.menuActions.itemByID(8511).invoke(); //sort c-styles
}
This will sort all the paragraph and character styles alphabetically in all open documents. It seems to work just fine, but I'm not sure about that 3rd line.
I'm familiar with processing documents by their index, like app.documents[i].blahblah, but in this case, that app.menuActions would just run those menuActions over and over on the activeDocument. I need to make each document active one-by-one to run the app.menuActions, but once I've changed the activeDocument, obviously the index numbers change and my "i" value is wrong.
My solution was to just run the function, then make the next document the activeDocument, over and over as many times as there are open documents.
Is that a reasonable solution? Or is there some better/more common way to do this?
Thanks!
