Well, this is untested, but I see that a Page object has a
removeOverride method. I'm not sure without testing whether calling that
will be the same as reapplying the master page or not, but you can try
it and see:
that should remove all overrides from all pages in the document, but as
I say, I'm not sure if that removes the overrides from the pages
themselves, or from everything on the pages.
If that doesn't work, I suppose one can just loop through the document
myPages = app.activeDocument.pages;
for (i = 0; i < myPages.length; i++) myPages[i].appliedMaster =
Give those a try and report back!
The removeOverride method appears to do nothing, but maybe I'm not implementing it correctly. I know only a little about scripts.
Looping through the document, though, does exactly what I wanted it to do. Thanks, Ariel!
@Ariel – hm, the documentation about pages says:
void removeOverride ()
Removes the override from a previously overridden master page item.
Did not test that, but maybe we have a bug here?
I don't have time to play around with this so much right now, but it could be that removeOverride on a doc page removes the overrides on the Page itself (not sure if that makes sense, but perhaps these days with the page tool, it's possible to get a different size page by applying a master with a different size). It doesn't remove the overrides on the pageItems.
But in any case, it occurred to me that what Ken wanted was to reapply the master, which is not necessarily the same thing as remove all overrides, is it? (for instance, in the case where a master page item has been deleted completely)
Completely outside of scripting, reapplying a master seems (at least in my case) to be different from removing master overrides. I went into some of the masters and changed margins. My changes don't show on the document pages. From the Pages palette flyout, Master Pages > Remove all local overrides is grayed out. However, Apply Master to Pages . . . causes my new margins to show on all the affected document pages. This was why I was asking about a solution to reapply masters, not remove overrides.
Ariel's 3-line script worked great and saved me an hour or two of tediously applying master pages through this 500-page book.