问题
When a document does not have any modal dialog window messages, app.activeDocument.close(SaveOptions.no)
works fine.
However, I have some InDesign documents that do have such windows appear, showing error messages about links that need to be updated, or incorrect styles. The above statement won't work in this case, as the windows prevent the script from accessing the document.
So, is there a way to iterate through all of the modal-dialogs in the active document? Here is what I have tried so far, which is not working:
if(xmlFile == "")
{
//alert("There is no linked XML file in this document,\n\ttry a different document.");
for(var i = 0; i < app.activeDocument.Windows.length; i++)
{
app.activeDocument.Windows[i].close();
}
app.activeDocument.close(SaveOptions.no);
exit();
}
回答1:
Ok, so the "user interaction level" of the application needs to be changed to "NEVER_INTERACT
" to ignore all modal dialog windows. Here is the modified code, which is now working:
if(xmlFile == "")
{
alert("There is no linked XML file in this document,\n\ttry a different document.");
// the original interaction and warning settings of the application
var oldInteractionPrefs = app.scriptPreferences.userInteractionLevel;
// prevent interaction and warnings from interrupting script
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// close the active document without saving
app.activeDocument.close(SaveOptions.no);
// reset interactions to original settings
app.scriptPreferences.userInteractionLevel = oldInteractionPrefs;
exit();
}
回答2:
Did you try it ?
app.activeDocument.windows.everyItem.close(SaveOptions.no);
来源:https://stackoverflow.com/questions/11769783/indesign-cs5-script-how-can-i-close-all-modal-dialog-windows-in-a-document