使用JXA关闭模式消息框

时间:2017-12-21 17:19:38

标签: macos automation jxa javascript-automation

编写执行应用程序功能的JXA自动化脚本。

var app = Application('Pages')
var doc = app.open(new Path('path to file'))
app.export(doc, {
        to: new Path('path to file'),
        as: dstFormat,
        withParameters: params
    })

app.export函数有时会出现错误消息框。抛出该消息框时脚本执行停止。如何自动关闭该消息框?

1 个答案:

答案 0 :(得分:0)

如果错误是由未找到'路径引起的?例如,您可以在app.open之前进行防御性检查:

// doesFileExist :: FilePath -> IO Bool
const doesFileExist = strPath => {
    const ref = Ref();
    return $.NSFileManager.defaultManager
        .fileExistsAtPathIsDirectory(
            $(strPath)
            .stringByStandardizingPath, ref
        ) && ref[0] !== 1;
};