I’m attempting to output a JPG preview of the InDesign page when the user either saves or closes the document. However, there appears to be no event fired when the document is saved, so I am trying to use just the close event for the document
Basic approach is to listen for the beforeClose
event, cancel the close process, run the export script, then close the document via script. But it seems like the event fires, and while I am catching it, InDesign continues on it’s merry way and closes the document on me, before I can get the export process to execute.
let docBeforeCloseEventListener = app.addEventListener("beforeClose", handleBeforeCloseEvent);
function handleBeforeCloseEvent(theEvent){
theEvent.preventDefault();
console.log('Document before close event received');
if (app.activeDocument) {
console.log('Closing document is ' + app.activeDocument.name);
}
exportPreview();
}
The beforeClose event is apparently cancelable according to the doco here https://developer.adobe.com/indesign/dom/api/e/Event/#methods, but I don’t know how to cancel it - .preventDefault()
looks to be the correct method, but I get the error “The requested action could not be completed because the object no longer exists.”
Anoyone managed to intercept the beforeClose and do anything useful to the document being closed?