: How to script a popup box before closing a document - InDesign I have used javascript to script before, using an eventlistener to say app.addEventListener( "beforeClose" , [function]); function
I have used javascript to script before, using an eventlistener to say
app.addEventListener( "beforeClose" , [function]);
function [functionname]()
etc...
What I need is a way to tell InDesign 'before closing the document, show a message box that say "did you proof your page?".
Which can then be OK'd and will continue the close process.
Does anyone have an idea how this could be done, or any alternatives that can produce the same effect?
More posts by @Pierce403
2 Comments
Sorted by latest first Latest Oldest Best
May I suggest to make this script even safer by first checking if the listener has been already added or not prior to add it ?
#target Indesign #targetengine "printConfirmation"
function main() {
var ev = app.eventListeners.itemByName ("onBeforePrintHandler" );
if ( ev.isValid ) return;
app.addEventListener("beforePrint", confirmPrint).name = "onBeforePrintHandler";
}
}
function confirmPrint(e) {
if (confirm ("Do you really want to print?") === false) {
e.stopPropagation();
e.preventDefault();
}
}
main();
Edit: Here is a script that asks for confirmation before closing a document:
#target Indesign #targetengine "closeConfirmation"
app.addEventListener("beforeClose", confirmClose);
function confirmClose(e) {
if(e.parent.constructor.name !== "LayoutWindow") return;
if (confirm ("Did you proof your page?") === false) {
e.stopPropagation();
e.preventDefault();
}
}
And here is the original post about the same thing for a beforePrint event:
#target Indesign
#targetengine "printConfirmation"
app.addEventListener("beforePrint", confirmPrint);
function confirmPrint(e) {
if (confirm ("Do you really want to print?") === false) {
e.stopPropagation();
e.preventDefault();
}
}
Note that the first one has an additional if clause, because when closing a document, both the Document and the LayoutWindow will trigger the event. So, if you would not cancel one of them, it would ask you twice.
You can move these to your startup scripts folder then they automatically register the events once InDesign is started.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.