Created
December 14, 2014 16:39
-
-
Save ofstudio/f136f473641109280333 to your computer and use it in GitHub Desktop.
Get password from OS X Keychain shell / bash function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get password from OS X Keychain function | |
# Replace %ACCOUNT_NAME% with account name of Keychain item | |
# See `man security` for more info | |
get_pw () { | |
security 2>&1 >/dev/null find-generic-password -ga "%ACCOUNT_NAME%" \ | |
| sed 's/password: "\(.*\)"/\1/' | |
} | |
# Don't store server credentials in plain text! | |
PASS=$(get_pw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
-w
rather than-g
to eliminate the need for output redirection orsed
. (Tested on High Sierra.)