1


     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();
}
Ian Campbell
  • 2,678
  • 10
  • 56
  • 104

2 Answers2

4

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();
}
Ian Campbell
  • 2,678
  • 10
  • 56
  • 104
  • 1
    This is correct and +1 for saving the original preference and putting it back like it was before. – Eric B. Jul 18 '14 at 19:00
1

Did you try it ?

app.activeDocument.windows.everyItem.close(SaveOptions.no);
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • I am not currently working with Extendscript, so I won't be able to test this unfortunately. It seems like an easy fix though! – Ian Campbell Jun 27 '14 at 16:25