I need to replace a couple existing master pages with other existing master pages.
I am familiar with how to replace master pages in general.

I have Master Pages - A, B, C, D, E, F.

I need to replace all occurrences of Master-F with Master-B and all occurrences of Master-E with Master-D. Document is several hundred pages in length. Document pages with these master assignments are non-contiguous. So, for example, I need to change the master assignment for page 4, 8, 10, 22, 40, 43, ~, 130, 190, 340, 347, etc.

  • I realize I can merely copy/paste contents between masters, or apply one master to another.
    (However, I want to keep existing masters as they are. Creating a new mater won't be of use.)

  • I realize I can drag/drop a master on a document page to replace the master.

  • I realize I can use Apply Master Page to... to apply a master page based upon document page numbers. The field to enter pages doesn't seem to accept something such as D-Master or D: as a viable input. (I've tried many variations.)

Factoring each and every page number for replacement would take as much time as manually drag/dropping masters. I can do all this manually, but I'd love something more automated.

Web searching hasn't presented anything of use. Often merely detailing the basics of theory and operations where Master pages are concerned. But, perhaps my web searching has been poor?

Is there an automated method of replacing all instances of one master page with another master page?

i.e. All Master-F assignments to Master-B assignments regardless of document page numbers?
Sort of like Find <> Replace, but with master page assignments only?

It had occurred to me that there may be a default script for such a thing, but based upon the script file names, I'm not seeing any default script for this specifically. I may be simply missing it though.

(I am using InDesign CS6, but have access to more recent versions if that's mandatory, Prefer CS6 though.)

  • 1
    I made this script for applying a master to every nth page in a document. I'm sure it could be changed to do what you want. But I'm going to bed now ...
    – Wolff
    Jan 22, 2021 at 0:40
  • Thanks @Wolff I'll take a look.
    – Scott
    Jan 22, 2021 at 0:41

1 Answer 1


Thanks to @Wolff and some more searching, I was able to edit an additional script I found on github, (which may be written originally by Joonas??) to accomplish this within InDesign.

[None] refers to the default (blank) Master Page named "[None]" and will swap like any other Master Page with this script. [None] does not mean "nothing" in this instance.

enter image description here

---- Updated for drop down labels and single "undo" step ----

// Modified from https://gist.github.com/joonaspaakko/f16b47be887a2058cd0c0ac6e7ab0343
// This script is a combination of resources from above URL and courtesy of Mads Wolff
// v1.1 Replaces all targeted Master assignments with new Master page assignment, regardless of page number

var master;
app.doScript(init, ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, 'Swap Master Pages');
function init() {
    var doc = app.activeDocument;
    var masters = get_masters(doc);

    dialog( masters );
    if ( master !== false ) {
        var pages = doc.pages;
        for (var i = 0; i < pages.length; i++) {
            var page = pages.item(i);

            if (page.pageItems.length < 1) {

                //Swap them
                if (page.appliedMaster === doc.masterSpreads.itemByName(oldMaster)) {

                    if (newMaster == "[None]") {
                        //Remove master assignment
                        page.appliedMaster = NothingEnum.NOTHING;
                    } else {
                        //Add new Master assignment
                        page.appliedMaster = doc.masterSpreads.itemByName(newMaster);
} // init()

function get_masters(doc) {
    var everyMaster = doc.masterSpreads.everyItem().name;
    var masters = ["[None]"];
    for (var i = 0; i < everyMaster.length; i++) {
    return masters;

function dialog(masters) {

    var dlg = new Window("dialog", "Swap Master Pages");
    dlg.orientation = "column";
    dlg.alignChildren = ["right","top"];
    dlg.spacing = 15;
    dlg.margins = 20;
    dlg.preferredSize.width = 220;
    var oldM = dlg.add("group", undefined, {name: "oldM"});
    var swapO = oldM.add("statictext", undefined, " Find Master ");
    var oldDropdown = oldM.add("dropdownlist", undefined, masters);
    var newM = dlg.add("group", undefined, {name: "newM"});
    var swapN = newM.add("statictext", undefined, " Assign Master ");
    var newDropdown = newM.add("dropdownlist", undefined, masters);
    var buttons = dlg.add("group");
    buttons.alignment = ["center","top"];
    var btn_cancel = buttons.add("button", undefined, "Cancel");
    var btn_ok = buttons.add("button", undefined, "Swap");

    oldDropdown.selection = 0;
    newDropdown.selection = 0;

    btn_cancel.onClick = function() {
        master = false;

    btn_ok.onClick = function() {
        oldMaster = oldDropdown.selection.toString();
        newMaster = newDropdown.selection.toString();


This does not alter Master Pages in any way. It merely alters the Master Page assignments applied to Document pages.

  1. Copy above script to a text file, title it SwapMasters.js.
  2. Add the file to [Hard Drive] / Applications / InDesign / Scripts / Scripts Panel
  3. Use this script by simply double-clicking it in the Scripts panel within InDesign
    (Window > Utilities > Scripts)
  • 1
    Nice! You didn't have to credit me, but thanks. 😀 Coding the interface often takes me longer than the function itself. A thing I would recommend you to add would be to run the init function like this: app.doScript(init, ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, 'Swap Master Pages');. This runs the script as one undoable action named "Swap Master Pages" in the menu, so if you regret running the script you won't have to undo through all the individual swaps.
    – Wolff
    Jan 22, 2021 at 7:31
  • 1
    Good point @Wolff Updated and added labels for the drop downs.
    – Scott
    Jan 22, 2021 at 8:14
  • I've used this script for that purpose in the past: graphicdesign.stackexchange.com/questions/35838/… Use the script > copy all required page numbers > Indesign: Apply master to pages > paste page numbers - More work, but given the type of task, it works fine. v.2.2. is behind the github gist URL. And also in the script changelog at the top I've put a link to v.1. in which you could pick one specific master. — @Wolff I've made a webapp for making SUI dialogs: scriptui.joonas.me.
    – Joonas
    May 20, 2021 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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