Create an Username and Password Entry Window Using AppleScript

I would like to make a dialog box input box that looks exactly like this in AppleScript:

Save the image in the upper left corner of the lock.

In addition, I need to be able to save both inputs.

I know that I can use tell application "System Events" to display dialog "blah blah" default answer "" end tell, but I can’t find a way to have multiple and marked fields.

+4
source share
1 answer

Naturally, AppleScript does not offer this feature with OSX 10.10 .

, , User Interaction (StandardAdditions.def, Script Editor.app File > Open Dictionary... > StandardAdditions.osax).

- - - - (, , , ):

display dialog ¬
    "Installer is ..." default answer ¬
    "" buttons {"Cancel", "Install Software"} ¬
    default button 2 ¬
    with hidden answer

, , , Pashua.

:

# Define the dialog using a textual definition similar to a properties file.
set dlgDef to "
# Window title (if you don't set one explicitly (even if empty), it'll be 'Pashua')
*.title = 

# Add the hint (static text).
st.type = text
st.text = Installer is trying to install new software. Type your password to allow this.

# Add the username field.
tfn.type = textfield
tfn.label = Name:

# Add the password field.
tfp.type = password
tfp.label = Password:

# Add the buttons.
cb.type = cancelbutton
db.type = defaultbutton
db.label = Install Software
"

# Show the dialog. 
# Return value is a record whose keys are the element names from the dialog
# definition (e.g., "tfn" for the  usernam text field) and whose
# values are the values entered (for input fields) or 
# whether a given button was clicked or not ("1" or "0")
set theResult to showDialog(dlgDef, "")

# Process the returned values.
if cb of theResult is "1" then
    display alert "User canceled the dialog."
else
    display alert "name=[" & tfn of theResult & "]; password=[" & tfp of theResult & "]"
end if

:

enter image description here


. ; . Read me.html Documentation.html .

+3

All Articles