2

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?

1
  • or even a "beforePrint" method, if one exists? Aug 23, 2017 at 13:11

2 Answers 2

4

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.

1
  • That is absolutely perfect! Worked like a charm! Aug 24, 2017 at 14:22
0

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();

Your Answer

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

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