• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cancel Printing in InDesign Dialog box "Print"

Guide ,
Jun 05, 2023 Jun 05, 2023

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!")

 

Capture d’écran 2023-06-05 à 14.50.16.png

 

Thanks in advance for any idea!

 

Best,

(^/)  The Jedi

TOPICS
Scripting

Views

200

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 05, 2023 Jun 05, 2023

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
...

Votes

Translate

Translate
Community Expert ,
Jun 05, 2023 Jun 05, 2023

Copy link to clipboard

Copied

Perhaps by attaching an AFTER_PRINT event to the doc? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 05, 2023 Jun 05, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2023 Jun 05, 2023

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

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

LATEST

Hi All,

 

Rob, your Script works fine with some adjustments.

 

Thanks a lot!

 

Best,

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines