close book in event handler is out of sync
function closeBooks() {
var books = app.books.everyItem().getElements();
var i, ilen = books.length;
for (i = 0; i < ilen; i++) {
if (books[i].modified) {
books[i].close(SaveOptions.ASK);
}
}
alert('done');
}
if you call the closeBooks function, everything works fine.
But if the function is used as a handler, the "done" message appears immediately, before the for loop complete.
try adding a beforeQuit eventListener:
app.addEventListener('beforeQuit', closeBooks);
and close InDesign having one or more modified books to see this (strange) behaviour.
The same function works fine if you target documents.
InDesign CC2021 16.2.1 on MacOs Catalina 10.15.7
1
vote
Roberto Bertazzoni
shared this idea