I would do it in this way:
// Your settings // --- var SEARCH_PATTERN = '2013'; var CHANGE_PATTERN = '2014'; // Set SEARCH // --- app.findTextPreferences = app.changeTextPreferences = null; app.findChangeTextOptions.includeMasterPages = true; app.findTextPreferences.findWhat = SEARCH_PATTERN; app.changeTextPreferences.changeTo = CHANGE_PATTERN; // Variables // --- var allDocs = app.documents, nDocs = allDocs.length, nFounds = [], counter = 0; // SEARCH ONLY MASTERPAGES IN ALL OPEN DOCS // --- for ( var i = 0; i < nDocs; i++ ) { var curDoc = app.documents[i], mPages = curDoc.masterSpreads.everyItem().pages.itemByRange(0, -1), target = mPages.textFrames.everyItem().paragraphs.everyItem(); target.changeText(); nFounds.push(target.changeText().length); } app.findTextPreferences = app.changeTextPreferences = null; for ( var i = 0; i < nFounds.length; i ++ ) { counter = counter + nFounds[i]; } alert( counter + " expressions have been changed." );
– Kai