Check/Destroy all opened dialogs
This is short one, but I use it in some of my scripts. Sometimes, script just hangs, or crashes, and if we used windows in script, they are not destroyed! They are still in memory and they will be there until we close InDesign. But, there is way to destroy all dialogs that are left in memory.
First, we can check is there some opened dialogs like this:
var openedDialogs = app.dialogs.length; alert(openedDialogs);
So, now we got dialogs count. If number is zero then we’re good, but what if it’s not?! There is very easy way to destroy all opened windows at once. All we have to do is first to check is there any opened window left, and if there is, any, we just destroy it. We select every item in app.dialogs with everyItem() and then we just destroy() them all😀
if (app.dialogs.length > 0) app.dialogs.everyItem().destroy();
That’s it’ Hope it helps😉