Last active
August 3, 2023 21:21
-
-
Save joonaspaakko/f16b47be887a2058cd0c0ac6e7ab0343 to your computer and use it in GitHub Desktop.
Indesign script that applies a master page to all empty pages in the document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/joonaspaakko/f16b47be887a2058cd0c0ac6e7ab0343 | |
// The script doesn't check for page items inside the current master. | |
// That means the current master could be filled with all kinds of graphics and this script considers it an empty page. | |
var master; | |
if (app.documents.length > 0) init(); | |
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); | |
// Not a single page item in sight... | |
if (page.pageItems.length < 1) { | |
// Apply master to the page. | |
if (master === "[None]") { | |
page.appliedMaster = NothingEnum.NOTHING; | |
} else { | |
page.appliedMaster = doc.masterSpreads.itemByName(master); | |
} | |
} | |
} | |
} | |
} // init() | |
function get_masters(doc) { | |
var everyMaster = doc.masterSpreads.everyItem().name; | |
var masters = ["[None]"]; | |
for (var i = 0; i < everyMaster.length; i++) { | |
masters.push(everyMaster[i]); | |
} | |
return masters; | |
} | |
function dialog(masters) { | |
var dlg = new Window("dialog", "Apply Master To Empty Pages.jsx"); | |
dlg.orientation = "row"; | |
var dropdown = dlg.add("dropdownlist", undefined, masters); | |
dropdown.selection = 0; | |
var buttons = dlg.add("group") | |
var btn_ok = buttons.add("button", undefined, "Apply Master"); | |
var btn_cancel = buttons.add("button", undefined, "Cancel"); | |
btn_ok.onClick = function() { | |
master = dropdown.selection.toString(); | |
dlg.close(); | |
} | |
btn_cancel.onClick = function() { | |
master = false; | |
dlg.close(); | |
} | |
dlg.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment