Skip to content

Instantly share code, notes, and snippets.

@bradwright
Created February 12, 2012 11:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwright/1808116 to your computer and use it in GitHub Desktop.
Save bradwright/1808116 to your computer and use it in GitHub Desktop.
How to get an OS X KeyChain entry in Emacs (useful for ERC etc.)
(defun chomp (str)
"Chomp leading and tailing whitespace from STR."
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" str)
(setq str (replace-match "" t t str))) str)
(defun get-keychain-password (account-name)
"Gets `account` keychain password from OS X Keychain"
(chomp
(shell-command-to-string
(concatenate
'string
"security 2>&1 >/dev/null find-generic-password -ga "
account-name
"| sed 's/^password: \\\"\\(.*\\)\\\"/\\1/'"))))
@bwolf
Copy link

bwolf commented Apr 25, 2014

Pretty useful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment