InDesign CC 2014 Extendscript: How to Reliably Close a Document After Asynchronous PDF Export

I wrote an indesign script that generates documents that need to be exported as PDF files. Export happens asynchronously so that the user can continue working. Generated documents remain open in the background during the export process and are closed only after the completion of the corresponding export.

How can I reliably fix an export failure, for example, when a user cancels a background export task from the background task bar?

The ImportExportTask.FAILED_EXPORT event does not work as described in the documentation, regardless of whether I am listening to the application or the exported document.

I also tried using IdleTasks to periodically check for status changes related to BackgroundTasks, but it makes me feel dirty and the IdleEvent.ON_IDLE events do not fire reliably enough for my purposes (based on my own experience).

I would really appreciate if anyone could help me with this, I have been spinning my wheels for too long on this.

Thank!

+4
source share
1 answer

Check the return value BackgroundTask waitforTask(), 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
+1
source

Source: https://habr.com/ru/post/1598397/


All Articles