0

Is there a expression/code in "apply master page" dialogue to apply selected master to every n pages, for example every 6th page? Any scripts suggestions will be appreciated!

  • Thanks for the script, Wolff! It works as described and is exactly what I needed! – Art Schneider Nov 12 '18 at 15:51
2

I have made a script that should accomplish what you want.

The main functionality of the script (the first part) is commented and pretty straight-forward (if you know javascript). I have added a small input dialog to make the script easy to use, but I haven't commented that part of the code.

Copy the code below to a text editor and save it as a .jsx file (for example ApplyMasterToEveryNthPage.jsx) in the folder for user scripts.

In InDesign, run the script and a dialog box will appear. Here you choose which master to use, the first page to apply it to and the interval (n).

Let me know if it works for you.


// APPLY MASTER TO EVERY NTH PAGE
// Copyright (c) 2017 Mads Wolff
// This script is distributed under the MIT License.


// MAIN FUNCTIONALITY

// Make a reference to the "pages" of the active document.
var pages = app.activeDocument.pages;

// Make a reference to the "masterSpreads" of the active document.
var masterSpreads = app.activeDocument.masterSpreads;

// Applies a master to every nth page starting at a certain page.
// Takes 3 arguments:
//   masterName   the name of the master spread
//   firstPage    the first page to apply the master to
//   interval     the interval (n) to apply the master at
function applyMasterToEveryNthPage(masterName, firstPage, interval) {

  // Make a reference to the "masterSpread" to apply.
  var masterSpread = masterSpreads.item(masterName);

  // Iterate through the "pages" at the chosen "interval", starting at the chosen "firstPage".
  for (var i = firstPage - 1; i < pages.length; i += interval) {

    // Make a reference to the "page".
    var page = pages.item(i);

    // Apply the "masterSpread" to the "page" by setting its "appliedMaster" attribute.
    page.appliedMaster = masterSpread;

  }

}


// DIALOG

// Stores all the names of the document's master spreads in an array.
function getMasterSpreadNames() {
    var masterSpreadNames = new Array;
    for(i = 0; i < masterSpreads.length; i++){
        masterSpreadNames.push(masterSpreads.item(i).name);
    }
    return masterSpreadNames;
}

// Displays the input dialog.
function displayDialog(){
    var dialog = app.dialogs.add({name:"Add Master To Every Nth Page"});
  var masterSpreadNames = getMasterSpreadNames();
    with (dialog) {
        with (dialogColumns.add()) {
      with (borderPanels.add()) {
        with (dialogColumns.add()) {
          staticTexts.add({staticLabel:"Master:"});
          staticTexts.add({staticLabel:"First page:"});
          staticTexts.add({staticLabel:"Interval:"});
        }
        with (dialogColumns.add()) {
          var masterNameDropdown = dropdowns.add({stringList: masterSpreadNames, selectedIndex: 0, minWidth: 200});
          var firstPageField = integerEditboxes.add({editValue: 1, minimumValue: 1, maximumValue: pages.length});
          var intervalField = integerEditboxes.add({editValue: 2, minimumValue: 1, maximumValue: pages.length});
        }
      }
    }
    }
    var dialogReturn = dialog.show();
    if (dialogReturn == true) {
        var masterName = masterSpreadNames[masterNameDropdown.selectedIndex];
        var firstPage = firstPageField.editValue;
        var interval = intervalField.editValue;
        dialog.destroy();
    applyMasterToEveryNthPage(masterName, firstPage, interval);
    } else {
        dialog.destroy();
    }
}

displayDialog();
  • ahhh... really appreciate it , it will save us all a lot of time... I test it and soon feedback too. – Roozbeh E Dec 17 '17 at 11:48
  • works great! thanks a lot for that simple user interface, that helps much more. just what I needed. – Roozbeh E Dec 17 '17 at 11:56
1

The best thing I can come up with is to generate the required page number sequence in 3-rd party software (like Excel) and then paste it in "apply..." field. Seems to work with documents several hundred pages long.

For example, in Excel put in A1 cell the initial page you want to apply master to.

Then, in B1 cell type A1+N.

Then apply and drag B1 by bottom right corner to the right for as many numbers as you wish. You'll have to copy the whole line of cells and replace tab symbols with commas.

enter image description here

Or you can use online tools like https://rechneronline.de/number-list/

  • thanks senge! looks a useful solution, while it is not what exactly i was looking about in InDesign... which I don't think it have that thou! – Roozbeh E Dec 16 '17 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.