Copy link to clipboard
Copied
Hi, everyone
How can I find-change only in the master pages?
for instance:
I want to change 2013 to 2014 but only in the master pages.
in all the opening files' master pages.
How can I do that?
Teetan
Hi Teetan,
To define a goal is more than half way of creating script.
Check this:
...app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "grow numbers on masters");
function main() {
catchOption = app.findChangeGrepOptions.includeMasterPages;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b\\d+\\b";
var
mTarget = app.documents.everyItem().masterSpreads.
Copy link to clipboard
Copied
Hi,
First use find(), after this filter results and finally change those one you need to.
There is no direct option.
Jarek
Copy link to clipboard
Copied
Thank you jarek
I will use synchronize in a book
Teetan
Copy link to clipboard
Copied
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,
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;
}
alert( counter + " expressions have been changed." );
– Kai
Copy link to clipboard
Copied
Hi,
I was to quick with my 1st answer, Kai is right.
changeText() method can be used with various targets. So if you prepare a target first - there is a direct option.
Jarek
Copy link to clipboard
Copied
Hi,
I realize, that here is no need for itemByRange.
So the target line could be writen shorter (no itemByRange needed):
target = curDoc.masterSpreads.everyItem().pages.everyItem().textFrames.everyItem();
– Kai
Copy link to clipboard
Copied
Hi, Jarek and Kai
I try the write script by my self like this but not work:
//---------------------------------------------------------------------------------------------------------
app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs");
function main(){
var _selection = app.selection[0];
for ( i = 1; i < app.documents.length; i++) {
myDoc = app.documents;
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b20+\\b";
var found = app.selection[0].findGrep();
for(var f=0;f<found.length;f++)
{
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+";
var foundnum = found
var newnum = parseInt(foundnum[0].contents) + 1;
app.changeGrepPreferences.changeTo = newnum.toString();
found
}
}
}
//----------------------------------------------------------------------------------------------------------
how can fix it?
Copy link to clipboard
Copied
Hi,
How can I combine the two scripts idea into one?
Teetan
Copy link to clipboard
Copied
@Teetan
Which numbers are you going to grow?
- each found on master pages
- only the one started with "20"
- is it posible to match a number 2099 there?
Jarek
Copy link to clipboard
Copied
Hi, I try again
changed it into this:
but not error
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Find-change num");
function main(){
for ( var i = 0; i < nDocs; i++ ) {
var curDoc = app.documents,
mPages = curDoc.masterSpreads.everyItem().pages.itemByRange(0, -1),
target = mPages.textFrames.everyItem().paragraphs.everyItem();
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b20+\\b";
var found = app.selection[0].findGrep();
for(var i=0;i<found.length;i++)
{
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+";
var foundnum = found
var newnum = parseInt(foundnum[0].contents) + 1;
app.changeGrepPreferences.changeTo = newnum.toString();
found.changeGrep();
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Teetan
Copy link to clipboard
Copied
Hi,
Hi, Jarek and Kai
what I want to change has growing requested, and I wish it has an undo possible.
thank you
Teetan
Copy link to clipboard
Copied
Hi
Jarek
may be 2099
Teetan
Copy link to clipboard
Copied
Hi,
I changed my current version in the meantime a bit, since the counter did show the wrong results, if you start the script a second time.
// 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,
target = curDoc.masterSpreads.everyItem().pages.everyItem().textFrames.everyItem();
var allFounds = target.changeText();
for (var n = 0; n < allFounds.length; n ++) {
var curFound = allFounds
; if (curFound.length != 0) {
counter += curFound.length;
}
}
}
app.findTextPreferences = app.changeTextPreferences = null;
alert( counter + " expressions have been changed." );
Teetan, I have no idea what you try to do with your second script. Please provide clear steps (1,2,3) and maybe a screenshot before / after.
And: Realize that 'undo' is available only per document. So if you have 20 docs open, you must undo in every document, even if we spent a doScript-Function!
Copy link to clipboard
Copied
Hi,
Kai
sorry I confuse you in some way
now I clarify it
1) I want to find-change the digit only in all the opening files' master
2) the digit has growing requested by years, I mean this year I find 2013 change to 2014 and next year I have to chan 2014 change to 2015
and finally I wish the script has UndoModes.ENTIRE_SCRIPT function
Regard
Teetan
Copy link to clipboard
Copied
Hi Kai
this script can find digit then change +1
//---------------------------------------------------------------------------------------------
app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs");
function main(){
var _selection = app.selection[0];
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "aged \\d+";
var found = app.selection[0].findGrep();
for(var i=0;i<found.length;i++)
{
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+";
var foundnum = found.findGrep();
var newnum = parseInt(foundnum[0].contents) + 1;
app.changeGrepPreferences.changeTo = newnum.toString();
found.changeGrep();
}
app.findGrepPreferences = changeGrepPreferences = null;
//-----------------------------------------------------------------------------------------------------
I get this idea, but I want it only work on master pages
Regard
Teetan
Copy link to clipboard
Copied
Hi Kai
can you help correct this script:
app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change digit" );
function main(){
// Set SEARCH
// ---
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2017";
app.changeTextPreferences.changeTo = "2018";
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2015";
app.changeTextPreferences.changeTo = "2016";
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2014";
app.changeTextPreferences.changeTo = "2015";
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2013";
app.changeTextPreferences.changeTo = "2014";
// 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,
target = curDoc.masterSpreads.everyItem().pages.everyItem().textFrames.everyItem();
var allFounds = target.changeText();
for (var n = 0; n < allFounds.length; n ++) {
var curFound = allFounds
if (curFound.length != 0) {
counter += curFound.length;
}
}
}
app.findTextPreferences = app.changeTextPreferences = null;
alert( counter + " expressions have been changed." );
}
Teetan
Copy link to clipboard
Copied
Hi Teetan,
To define a goal is more than half way of creating script.
Check this:
app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "grow numbers on masters");
function main() {
catchOption = app.findChangeGrepOptions.includeMasterPages;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b\\d+\\b";
var
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(),
mFound = mTarget.findGrep(),
mConFound = [],
len = mFound.length;
if (len && mFound[0].constructor.name == "Array")
while (len-->0)
mConFound = mConFound.concat(mFound[len]);
len = mConFound.length;
while (len-->0) {
mConFound[len].contents = String(Number(mConFound[len].contents) + 1);
}
app.findChangeGrepOptions.includeMasterPages = catchOption;
}
Jarek
Copy link to clipboard
Copied
Hi Jreak,
it's what I want
thank you so much
appreciate
Teetan
Copy link to clipboard
Copied
Hi Jreak
Can you tell me
this script can only work on:
//---------------------------------------------------------------------------------------------------
app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change digit" );
function main(){
// Set SEARCH
// ---
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2017";
app.changeTextPreferences.changeTo = "2018";
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2015";
app.changeTextPreferences.changeTo = "2016";
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.findWhat = "2014";
app.changeTextPreferences.changeTo = "2015";
//========================================================
app.findTextPreferences = app.changeTextPreferences = null; // only work on this part
app.findChangeTextOptions.includeMasterPages = true; // the rest are unfunction
app.findTextPreferences.findWhat = "2013"; // can you tell me why?
app.changeTextPreferences.changeTo = "2014"; // can you make it happen, in case of find something not a digit
//============================================================
// 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,
target = curDoc.masterSpreads.everyItem().pages.everyItem().textFrames.everyItem();
var allFounds = target.changeText();
for (var n = 0; n < allFounds.length; n ++) {
var curFound = allFounds
if (curFound.length != 0) {
counter += curFound.length;
}
}
}
app.findTextPreferences = app.changeTextPreferences = null;
alert( counter + " expressions have been changed." );
}
//---------------------------------------------------------------------------------------------------
regard
Teetan
Copy link to clipboard
Copied
Jarek, your version ist much shorter, than my script, great
I have this in the meantime:
if ( app.documents.length > 0 ) {
if ( app.scriptPreferences.version >= 6 ) {
app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Search in Masterpages" );
}
else {
main();
}
} else {
alert ( "No documents open!" );
}
function main() {
// Your settings
// ---
var SEARCH_PATTERN = '\\b201[4-6]\\b';
// Set SEARCH
// ---
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences.findWhat = SEARCH_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,
target = curDoc.masterSpreads.everyItem().pages.everyItem().textFrames.everyItem();
var allFounds = target.findGrep();
for ( var n = 0; n < allFounds.length; n ++ ) {
var framesFound = allFounds
; if ( framesFound.length > 0 ) {
for ( var j = framesFound.length-1; j >= 0 ; j-- ) {
var curFound = framesFound
; var newNumber = (parseInt( curFound.contents) +1).toString();
curFound.contents = newNumber;
} // for
counter += framesFound.length;
} // if
} // for
} // for
app.findGrepPreferences = app.changeGrepPreferences = null;
alert( counter + " expressions have been changed." );
} // main
Copy link to clipboard
Copied
Hi, Kai
what if find-change something not a digit, but only in master?
Teetan
Copy link to clipboard
Copied
Teetan, first of all, after Jareks code, I correct my version a bit. Nevertheless my version is a bit longer than Jareks, because I check some things more, have a alert at the end and I’m not able to write such short scripts as Jarek (as a advanced beginner I have always problems with while loops …).
The trick ist the line nr. 16 SEARCH_Pattern. Here you can enter the right expression. E.g. if you want to find 2013 - 2016 change [4-6] to [3-6]. However: The script assumes, that you want to grow up numbers +1. So if you want to change other things on the masterpages, all those scripts from today won’t work and must be modified > new goals >> new scripts 😉
if ( app.documents.length > 0 ) {
if ( app.scriptPreferences.version >= 6 ) {
app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Search in Masterpages" );
}
else {
main();
}
} else {
alert ( "No documents open!" );
}
function main() {
// Your settings
// ---
var SEARCH_PATTERN = '\\b201[4-6]\\b';
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences.findWhat = SEARCH_PATTERN;
var target = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
var allFounds = target.findGrep();
var counter = 0;
for ( var n = 0; n < allFounds.length; n ++ ) {
var framesFound = allFounds
; if ( framesFound.length > 0 ) {
for ( var j = framesFound.length-1; j >= 0 ; j-- ) {
var curFound = framesFound
; curFound.contents = String( Number( curFound.contents) + 1 );
}
counter += framesFound.length;
} // if
} // for
app.findGrepPreferences = app.changeGrepPreferences = null;
alert( counter + " expressions have been changed." );
} // main
but not today. Sunny wheather. Let’s go outside .
Copy link to clipboard
Copied
thanks
Kai
Find more inspiration, events, and resources on the new Adobe Community
Explore Now