当用作字符串参数时,displayDialog方法的返回值导致错误-1700

时间:2019-03-13 00:56:46

标签: javascript jxa

当我尝试打印Var 'password'时说

  

错误-1700:无法转换类型。

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


var text = Application('System Events')
//prompt
var password = app.displayDialog('enter your password', {defaultAnswer: " "});
text.keystroke(password)
//returned message is Error -1700: Can't convert types.

1 个答案:

答案 0 :(得分:1)

displayDialog命令返回一条AlertReply记录,在JXA中如下所示:

{"buttonReturned":"OK", "textReturned":"password"}

要获取在对话框中输入的值,请尝试将.textReturned附加到displayDialog调用中,如下所示:

var password = app.displayDialog('enter your password', {defaultAnswer: " "}).textReturned;