Derek Brown
Derek Brown

Reputation: 41

InDesign CC 2014 Extendscript: How to reliably close document after asynchronous PDF export

I've written an indesign script which generates documents that need to be exported as PDF files. Exports happen asynchronously so that the user can continue working. The generated documents remain open in the background during the export process, and are closed only once the associated export is complete.

How can I reliably capture export failure, such as when a user cancels a background export task from the background tasks panel?

The ImportExportTask.FAILED_EXPORT event doesn't appear to work as described by the documentation, regardless of whether I listen on the app or the document being exported.

I've also tried using IdleTasks to periodically check for changes in status of the associated BackgroundTasks, but it makes me feel dirty, and IdleEvent.ON_IDLE events don't trigger reliably enough for my purposes (based on my own experience).

I'd really appreciate it if anyone could help me with this, I've been spinning my wheels on this one for far too long.

Thanks!

Upvotes: 4

Views: 730

Answers (1)

Tobias Kienzler
Tobias Kienzler

Reputation: 27413

Check the return value of BackgroundTask's waitforTask(), a TaskState:

TaskState.CANCELLED  | Task was cancelled (either before it ran or during execution
TaskState.CANCELLING | Task was signalled to cancel but did not stop yet
TaskState.COMPLETED  | Task completed execution (successfully or with errors)
TaskState.QUEUED     | Task was queued and is waiting to be scheduled for execution
TaskState.RUNNING    | Task is running
TaskState.WAITING    | Task is waiting

Upvotes: 1

Related Questions