I'm working on a script that searches master spreads for specific text. Once it is found, the master spread name is returned. Now I am stuck trying to search the pages to find where that master spread is first applied. Any help?
var doc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "custom text";
var finds = doc.findText();
if (finds.length > 0) {
var mspage = finds[0].parentTextFrames[0].parent.name;
var dpage = doc.pages[0].appliedMaster.name; //This of course is not right, it's returning the name of the master spread for whatever page is currently selected. So how do I set the current page to the page that first uses the found master spread (mspage)?
You'll have to search for it.
var i, dpage;
for (i=0; i<=doc.pages.length; i++) {
if (doc.pages[i].appliedMaster == mspage) {
dpage=doc.pages[i];
break;
}
}
Though if it never finds one, you'll get an error.