3

I've just about finished an ExtendScript project for Adobe InDesign CS6. One of the last few bugs I need to squash comes in the form of this error message:

Cannot handle request because a modal dialog or alert is active

What happens in the script is that it opens an InDesign file, does some work to it, then saves and closes it. However, if the file has some text that uses a font which is not installed on my system, then a window pops up alerting me to that fact. Because of this popup window, the entire script is interrupted and errors out with the above message.

Is there any way for the script to handle this? Perhaps to keep an eye out for a popup window and just dismiss it (by doing the equivalent of clicking "OK" on the window) before it continues on with the rest of the script?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sturm
  • 689
  • 2
  • 23
  • 52

1 Answers1

5

Try this:

var oldUserInteractionLevel = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// Put code here that would create the alert.
// E.g. If the alert is caused by opening the document, then open the document here.
app.scriptPreferences.userInteractionLevel = oldUserInteractionLevel;
// After this line you can safely show dialogues to the user.
dln385
  • 11,630
  • 12
  • 48
  • 58
  • Sorry, but my script has its own windows that I _do_ want to show to the user for gathering data. Setting that enum anywhere in the script breaks it, so I that solution won't work for my purposes. – Sturm Jun 25 '13 at 18:43
  • I just gave it a shot and, much to my surprise, that seems to work! Thanks! – Sturm Jun 25 '13 at 19:10
  • Glad to hear it! I figured that `NEVER_INTERACT` is a misnomer. It actually means, "While this setting is present, don't interact under any circumstances". You can just as easily change the value back again and then interact with the user. – dln385 Jun 25 '13 at 19:33