Skip to main content
Inspiring
October 12, 2009
Answered

Need script to insert pages with specified master

  • October 12, 2009
  • 2 replies
  • 8194 views

Several years ago, someone here (I think Dave, maybe Ole) helped me out by giving me a short script that when run added a blank page (with a specified master page different from the previous page) after each page of a document.

I've had an emergency reformat of my system and have lost that script which I need constantly for work projects. I tried searching here, but it was before the current forum setup (I think around 2 years ago) and I can't find a way to get to the archives.

If anyone can either provide me with the java script code for this or point me to the old messages about it, I'd be very appreciative.

And, BTW, I am now using CS4 (though I'm sure the script I've been using was from an older version).

Thank you.

This topic has been closed for replies.
Correct answer Harbs.

Here: I don't know about the original, but I just whipped this together for you:

var doc = app.documents[0];
var masterNames = doc.masterSpreads.everyItem().name;
var d = app.dialogs.add({name:"pick a master spread"});
d.dialogColumns.add().staticTexts.add({staticLabel:"Master Pages:"});
var dd = d.dialogColumns.add().dropdowns.add({stringList:masterNames});
if(d.show()){
     var index = dd.selectedIndex;
     d.destroy();
} else {
     d.destroy();exit();
}
var master = doc.masterSpreads.item(index);
for(var i=doc.pages.length-1;i>=0;i--){
     doc.pages.add(LocationOptions.AFTER,doc.pages,{appliedMaster:master});
}

HTH,

Harbs

2 replies

Harbs.
Harbs.Correct answer
Brainiac
October 12, 2009

Here: I don't know about the original, but I just whipped this together for you:

var doc = app.documents[0];
var masterNames = doc.masterSpreads.everyItem().name;
var d = app.dialogs.add({name:"pick a master spread"});
d.dialogColumns.add().staticTexts.add({staticLabel:"Master Pages:"});
var dd = d.dialogColumns.add().dropdowns.add({stringList:masterNames});
if(d.show()){
     var index = dd.selectedIndex;
     d.destroy();
} else {
     d.destroy();exit();
}
var master = doc.masterSpreads.item(index);
for(var i=doc.pages.length-1;i>=0;i--){
     doc.pages.add(LocationOptions.AFTER,doc.pages,{appliedMaster:master});
}

HTH,

Harbs

Jongware
Adobe Expert
October 12, 2009

Oh, sure, it has a dialog, but ...

Hm -- seems to work exactly as mine.

.. Oh well.

Cyndee MAuthor
Inspiring
October 12, 2009

I have located the old PageMaker scripts that I had used for this purpose. If it will help anyone to post them, please let me know and I will do so.

Jongware
Adobe Expert
October 12, 2009

Aaahhh ... PageMaker scripting. Now there was a challenge -- I don't think I ever could write the thing I intended with that.

This quick javascript works on CS, but I don't think the syntax has changed (much) for CS4. Yell if it doesn't work.

Be sure to fill in the right 'blank page' name in the first line! That includes the prefix and the hyphen -- the script will alert you if you got it wrong

//DESCRIPTION: Add Blank Master Page after each page

masterPageName = "A-AddMe";
masterPage = app.activeDocument.masterSpreads.item(masterPageName);
if (masterPage == null)
{
alert ('"'+masterPageName+'" is not a valid master...');
exit(0);
}

// Start at the end:
currentPage = app.activeDocument.pages.length-1;
while (currentPage >= 0)
{
theNewPage = app.activeDocument.pages.add (LocationOptions.AFTER, app.activeDocument.pages[currentPage]);
theNewPage.appliedMaster = masterPage;
currentPage--;
}


Copy, paste into a plain text editor (InDesign's ESTK is good) and save as "insertBlanksAfterAll.jsx" in your Scripts folder. When saved in the right folder, it will automatically become available in the Scripts Panel.

Harbs.
Brainiac
October 12, 2009

Jong:

Too slow...

Harbs