less than 1 minute read

This function will use AppleScript to present a password entry dialog to make your scripts a little more user friendly:

function gui_password {
    if [[ -z $1 ]]; then
        gui_prompt="Password:"
    else
        gui_prompt="$1"
    fi
    PW=$(osascript <<EOF
    tell application "System Events"
        activate
        text returned of (display dialog "${gui_prompt}" default answer "" with hidden answer)
    end tell
EOF
    )

    echo -n "${PW}"
}

Via awesome-macos-command-line.

Tags: ,

Categories:

Updated:

Leave a comment