Skip to main content
shelbycott
Known Participant
December 13, 2019
Answered

exportFile() with showOptions - Terminate on cancel

  • December 13, 2019
  • 1 reply
  • 1204 views

Hi everyone,

 

I'm in the process of creating an InDesign panel with ExtendScript and am having issues exporting PDFs. My question is, is there any way to determine whether the user clicked cancel when exporting with options?

 

Here's the script below.

app.activeDocument.exportFile(ExportFormat.pdfType, File(exportPath), true);

 

This brings up the following window:

 

Although the InDesign file does not export on cancel, the remainder of my script still runs. The goal is to terminate the script on cancel. Any push in the right direction is greatly appreciated. Thanks so much!

This topic has been closed for replies.
Correct answer brian_p_dts

The only problem is that this doesn't apply when overwriting a file, but I might just have to figure out how to make this work. Thank you for your help!


You can check if the file exists before exporting and its modified date and check against both: 

 

 

 

 

 

var fileToExport = File(exportPath);
if (fileToExport.exists) {
    var modDate = fileToExport.modified.toString();
}
app.activeDocument.exportFile(ExportFormat.pdfType, fileToExport, true);
if (!fileToExport.exists || fileToExport.modified.toString() == modDate) {
    exit();
}​

 

 

 

 

 

 

1 reply

brian_p_dts
Community Expert
Community Expert
December 13, 2019

Try wrapping the call in a negative boolean if statement, like so: 

 

if (!app.activeDocument.exportFile(ExportFormat.pdfType, File(exportPath), true)) {
   exit();
}
//do more stuff
shelbycott
Known Participant
December 13, 2019

Thanks for the reply! Just tried this and unfortunately it's returning false regardless of whether I click "Export" or "Cancel."

brian_p_dts
Community Expert
Community Expert
December 13, 2019

Oh right, that doesn't return null. You can check if the file exists after the fact. 

 

var fileToExport = File(exportPath);
app.activeDocument.exportFile(ExportFormat.pdfType, fileToExport, true);
if (!fileToExport.exists) {
    exit();
}
//do more stuff