Wait for Process / Fix InDesign Threading Problems
var oldPreflight = app.activeDocument.preflightOptions.preflightOff;
app.activeDocument.preflightOptions.preflightOff = false;
// wait a maximum of 20 second for the preflight process. Before it runs, all Transactions should be closed.
app.activeDocument.activeProcess.waitForProcess(20);
app.activeDocument.preflightOptions.preflightOff = oldPreflight ;