欢迎各位兄弟 发布技术文章
这里的技术是共享的
Use the APPLESCRIPT JAVASCRIPT Protect potentially sensitive information from prying eyes by using the APPLESCRIPT JAVASCRIPTdisplay dialog
command’s optional default answer
parameter to collect text, such as a username or email address, as your script runs. As demonstrated by Figure 23-1, Listing 23-1, and Listing 23-2, the inclusion of the default answer
parameter automatically adds a text entry field to the resulting dialog. Any string you provide for the parameter appears in the text field when the dialog displays. Providing an empty string (""
) produces an empty text field. When the dialog dismisses, any text from the field is returned in a text returned
property of the display dialog
command’s result.set theResponse to display dialog "What's your name?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
--> {button returned:"Continue", text returned:"Jen"}
display dialog "Hello, " & (text returned of theResponse) & "."
var app = Application.currentApplication()
app.includeStandardAdditions = true
var response = app.displayDialog("What's your name?", {
defaultAnswer: "",
withIcon: "note",
buttons: ["Cancel", "Continue"],
defaultButton: "Continue"
})
// Result: {"buttonReturned":"Continue", "textReturned":"Jen"}
app.displayDialog("Hello, " + (response.textReturned) + ".")
Prompting for Hidden Text
display dialog
command’s default answer
parameter in conjunction with the hidden answer
parameter to show bullets instead of plain text in the dialog’s text field. See Figure 23-2, Listing 23-3, and Listing 23-4.display dialog "Please enter a passphrase to use this script." default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue" with hidden answer
--> Result: {button returned:"Continue", text returned:"MySecretPassphrase"}
var app = Application.currentApplication()
app.includeStandardAdditions = true
app.displayDialog("Please enter a passphrase to use this script.", {
defaultAnswer: "",
withIcon: "stop",
buttons: ["Cancel", "Continue"],
defaultButton: "Continue",
hiddenAnswer: true
})
// Result: {"buttonReturned":"Continue", "textReturned":"MySecretPassphrase"}