Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'How to pull a password from Keychain to use in a script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How to pull a password from Keychain to use in a script
Authored by: mike_savory on Jul 25, '13 05:23:10PM

Yes, this just gives you the password, no grep/awk/sed required.

$ security find-generic-password -wa $USER

Or if you wanted to stay with the original and just use AWK (like the previous poster used SED) then this also works with Bash (just for info, and because I like AWK)

$ security find-generic-password -ga $USER 2>&1 | awk 'BEGIN{FS="\042"} /password/ {print $2}'

It tells AWK to use " as a field separator (the FS = 042 bit) matches the password line and prints the second item on that line, using " to count items

Mike



[ Reply to This | # ]