Skip to content

Instantly share code, notes, and snippets.

@traycho
Last active December 16, 2019 15:46
Show Gist options
  • Save traycho/5c305c8097f39f1789d863c8089e095b to your computer and use it in GitHub Desktop.
Save traycho/5c305c8097f39f1789d863c8089e095b to your computer and use it in GitHub Desktop.
Get password from macOS keychain using a bash script.
#!/bin/bash
PASSWORD=$(keychainPassword)
echo $PASSWORD
# Fetch current user password from keychain
keychainPassword () {
return $(security 2>&1 >/dev/null find-generic-password -ga $USER | sed 's/password: "\(.*\)"/\1/')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment