Mac OS X Javascript for Automation displayDialog

时间:2015-06-01 22:28:44

标签: javascript macos automation jxa

我试图获得一个简单的对话框来显示我正在处理的工作流程,但是使用JXA我不断收到错误:期望对象说明符,参数没有对象说明符。我不知道传递对象Specifier的内容。我的代码如下,在第11行我需要调用对话框

function run() {

    app = Application.currentApplication();
    app.includeStandardAdditions = true;
    //Error Here
    var who = app.displayDialog('Whose server is this?', {
        withTitle: 'Whose Server...'
    })

    return who
}

2 个答案:

答案 0 :(得分:1)

阅读这篇非正式的cookbook about User-Interactions,它可以帮助我了解这些警示事项。

详情:

function prompt(text, defaultAnswer) {
  var options = { defaultAnswer: defaultAnswer || '' }
  try {
    return app.displayDialog(text, options).textReturned
  } catch (e) {
    return null
  }
}

答案 1 :(得分:-2)

来自 Gary @ macmost.com https://www.youtube.com/watch?v=GcPUJzmEuKE @ 8:47

app = Application.currentApplication();
app.includeStandardAdditions = true;

color = app.displayDialog("What is your favorite color?", { defaultAnswer: "" }).textReturned;

if (color == "red") {
    app.displayDialog("I like red too!");
} else {
    app.displayDialog("Interesting, I like red myself.");
}