使用JXA关闭模式消息框

问题描述 投票:0回答:1

编写执行应用程序功能的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函数有时会出现错误消息框。抛出该消息框时脚本执行停止。如何自动关闭该消息框?

macos automation jxa javascript-automation
1个回答
0
投票

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

// doesFileExist :: FilePath -> IO Bool
const doesFileExist = strPath => {
    const ref = Ref();
    return $.NSFileManager.defaultManager
        .fileExistsAtPathIsDirectory(
            $(strPath)
            .stringByStandardizingPath, ref
        ) && ref[0] !== 1;
};
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.