unixorn/tumult.plugin.zsh

View on GitHub
bin/ask-password

Summary

Maintainability
Test Coverage
#!/bin/bash
#
# Make it easy to ask for a password

set -e

if [[ "$(uname -s)" != 'Darwin' ]]; then
  echo 'Sorry, this script only works on macOS'
  exit 1
fi

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

echo -n "${PW}"