【问题标题】:Close modal message box with JXA使用 JXA 关闭模式消息框
【发布时间】:2017-12-30 19:56:15
【问题描述】:

编写执行应用程序功能的 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 javascript-automation


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2018-08-17
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      相关资源
      最近更新 更多