InDesign CS5 Script: How can I close all modal dialog windows in a document?

会有一股神秘感。 提交于 2019-12-11 05:38:36

问题



     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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!