Copy link to clipboard
Copied
Hi All,
No idea about this:
My Script step:
app.activeDocument.print(true);
Is there a way to get an alert (in my Script) if I cancel (or not) the printing in the InDesign Dialog Box "Print", like:
if the printing is canceled (after clicking on the "Cancel" button) alert("Printing canceled!")
esle alert("Printing done!")
Thanks in advance for any idea!
Best,
(^/) The Jedi
Hi @FRIdNGE , In order to check whether the Print dialog was cancelled, you might need a combination of print events and an idle task. I don’t think an afterPrint event will let you know if the dialog was cancelled. Not sure if there is an easier way to do it, but this works for me:
#targetengine "checkprint"
app.eventListeners.add("beforePrint", checkModal);
var iTask;
/**
* Before the print dialog add an afterPrint event and an idleTask
* to check for the dialog cancel
* @ param e bef
...
Copy link to clipboard
Copied
Perhaps by attaching an AFTER_PRINT event to the doc?
Copy link to clipboard
Copied
Take a look here...
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#Event.html#d1e34342
Regards,
Mike
Copy link to clipboard
Copied
Hi @FRIdNGE , In order to check whether the Print dialog was cancelled, you might need a combination of print events and an idle task. I don’t think an afterPrint event will let you know if the dialog was cancelled. Not sure if there is an easier way to do it, but this works for me:
#targetengine "checkprint"
app.eventListeners.add("beforePrint", checkModal);
var iTask;
/**
* Before the print dialog add an afterPrint event and an idleTask
* to check for the dialog cancel
* @ param e beforePrint event
*/
function checkModal(e){
if (!e.propagationStopped) {
app.removeEventListener("beforePrint", checkModal);
app.eventListeners.add("afterPrint", checkPrint);
iTask = makeIdleTask("NoPrint", 10)
iTask.addEventListener(IdleEvent.ON_IDLE, checkDialog);
}
}
/**
* Check if the printing happened, if it has remove listeners
* @ param e afterPrint event
*/
function checkPrint(e){
if (!e.propagationStopped) {
alert("Printing")
app.removeEventListener("afterPrint", checkPrint);
app.idleTasks.itemByName("NoPrint").remove();
//iTask = null;
}
}
/**
* Check if the print dialog was cancelled—the modal state is false
* @ param e idle event
*/
function checkDialog(e){
if (!app.modalState) {
alert("Cancelled")
app.removeEventListener("afterPrint", checkPrint);
app.idleTasks.itemByName("NoPrint").remove();
//iTask = null;
}
}
/**
* Makes a new named idleTask
* @ param the task name
* @ param the sleep time
* @ return the named idleTask
*/
function makeIdleTask(n, s){
var it;
try {
app.idleTasks.add({name:n, sleep:s})
}catch(e) {
it = app.idleTasks.item (n);
}
return app.idleTasks.item (n);
}
Copy link to clipboard
Copied
Hi All,
Rob, your Script works fine with some adjustments.
Thanks a lot!
Best,
(^/)