Last active
May 11, 2020 10:28
-
-
Save joonaspaakko/efc6eb11759965d54b20 to your computer and use it in GitHub Desktop.
Indesign script that generates a text file with information on which pages each master page is applied to.
This file contains 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/efc6eb11759965d54b20 | |
// Improvements?: | |
// Currently the script checks every single page, even though it only prints results per one selected master. | |
// Instead of that, it could print resuls for every single master on one go. This would be slightly easier | |
// for the user and it probably wouldn't have an impact on the script performace. | |
// Current document | |
var doc = app.documents[0]; | |
// List of master pages | |
var docMasters = doc.masterSpreads.everyItem().name; | |
// Dialog | |
dialog = "dialog { \ | |
text: 'Master page numbers', \ | |
alignChildren:['left','top'], \ | |
decisions: Panel { \ | |
alignChildren:['left','center'], \ | |
group: Group { \ | |
dropdown: DropDownList { preferredSize:[200,24], properties: { items: ['" + docMasters.join("','") + "'] } } \ | |
check: Button { text: 'Check' }, \ | |
cancel: Button { text: 'Cancel' }, \ | |
} \ | |
} \ | |
}"; | |
var dlg = new Window( dialog ); | |
var check; | |
// Check button click event... | |
dlg.decisions.group.check.onClick = function(){ | |
check = true; | |
dlg.close(); | |
return check; | |
}; | |
// Open dialog... | |
dlg.show(); | |
// Check button was clicked.... | |
if ( check ){ | |
// Selected master page | |
var dlgMaster = dlg.decisions.group.dropdown.selection.toString(); | |
// This array is later on filled with page numbers belonging to selected master page | |
var masters = []; | |
var pagesLength = doc.pages.length; | |
// Loop through all pages... | |
for ( var i = 0; i < pagesLength; i++ ) { | |
// Find out what master each page has | |
var pageMaster = doc.pages[ i ].appliedMaster.name; | |
// If page master is the same selected earlier in the dialog, push it to dlgMaster array. | |
pageMaster == dlgMaster && masters.push( ' ' + ( i+1 ) ); | |
}; | |
// Print out the answer... | |
alert( dlgMaster + '\n' + ( masters == '' ? 'Has not been applied to any page directly.' : 'Is applied to page(s): \n\n' + masters ) ) | |
}; |
Author
joonaspaakko
commented
Jul 17, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment