我刚刚完成了Adobe InDesign CS6的ExtendScript项目。我需要压缩的最后几个错误之一是以此错误消息的形式:
无法处理请求,因为模式对话框或警报处于活动状态
脚本中发生的事情是它打开一个InDesign文件,对它做一些工作,然后保存并关闭它。但是,如果文件中有一些文本使用的字体未安装在我的系统上,则弹出一个窗口提醒我这个事实。由于此弹出窗口,整个脚本被中断并且上述消息出错。
脚本有没有办法处理这个问题?也许要留意一个弹出窗口,然后忽略它(通过在窗口上单击“确定”等效),然后再继续使用脚本的其余部分?
试试这个:
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.