Mac: Ask user for password via GUI
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}"
}
Leave a comment