var app = Application.currentApplication() app.includeStandardAdditions = true app.activate() ObjC.import('stdio') ObjC.import('stdlib') var opts = {{json .Options}} {{- if .IconPath}} opts.withIcon = Path({{json .IconPath}}) {{- end}} function dialog(text) { try { var res = app.displayDialog(text, opts) } catch (e) { if (e.errorNumber === -128) $.exit(1) $.dprintf(2, e) $.exit(-1) } if (res.gaveUp) { $.exit(5) } if (res.buttonReturned === {{json .Extra}}) { $.puts({{json .Extra}}) $.exit(1) } return res.textReturned } var start = Date.now() opts.defaultAnswer = '' var username = dialog('Username:') {{- if .Options.Timeout}} opts.givingUpAfter -= (Date.now() - start) / 1000 |0 {{- end}} opts.hiddenAnswer = true var password = dialog('Password:') username + {{json .Separator}} + password