0

When I try printing the Var 'password' it says

Error -1700: Can't convert types.

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.
bacongravy
  • 893
  • 8
  • 13
  • Are you trying to log the password variable? Perhaps instead of text.keystroke() you want to use `console.log(password)`. To view the things that you have logged, choose "Show Log" from the "View" menu, and then select the "Messages" tab in the bottom half of the window, and re-run the script. Alternatively, the last statement of your script is its return value, so if you just make the last line of your script `password;` (no "var"!) then you should see its value printed in the bottom of the ScriptEditor window when the script finishes. – bacongravy Mar 16 '19 at 21:51

1 Answers1

1

The displayDialog command returns an AlertReply record, which looks like this in JXA:

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

To get the value entered in the dialog, try appending .textReturned to the displayDialog invocation, like this:

var password = app.displayDialog('enter your password', {defaultAnswer: " "}).textReturned;
bacongravy
  • 893
  • 8
  • 13