Site logo

Background tasks

If you want to use the 'background tasks' functionality, you'll need to use document.asynchronousExportFile(). AsynchronousExportFile returns a background task, which has the method waitForTask().

You can use it something like this:

t = app.activeDocument.asynchronousExportFile(ExportFormat.pdfType, File("~/Desktop/Test.pdf"));
alert("Task is done")  

This will export your document as a PDF using a background task, wait for the export to complete, and then pop up an alert.  The problem is that you loose the advantages of a background task (namely, you can do other things while the file is exporting in the background).

The backgroundTask object has a property status, which returns the status of the task, including TaskState.COMPLETED. You could probably add an event listener to check for the state change from TaskState.RUNNING to TaskState.COMPLETED. When I get a bit more time later, i'll check it out and try to provide some sample code.

Automatic dialog after background export (exportPop.jsx) by John Hawkinson
This script will automatically pop up a dialog box after every export finishes (PDF, IDML, whatever). It also makes sure that the Background Tasks window is turned on.