Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Last active March 23, 2019 05:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxmph/b1370eb9819c6160af30b21d1f58af67 to your computer and use it in GitHub Desktop.
Save pdxmph/b1370eb9819c6160af30b21d1f58af67 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
account = ARGV[0] # account name, e.g. pdxmph@gmail.com
server = ARGV[1] # account server, e.g. imap.gmail.com
user = `whoami`.strip!
keychain_path = "#{ENV['HOME']}/Library/Keychains/login.keychain"
params = {'security' => '/usr/bin/security',
'command' => 'find-internet-password',
'account' => account,
'server' => server,
'keychain' => keychain_path}
output = `sudo -u #{user} #{params['security']} 2>&1 >/dev/null -q #{params['command']} -g -a #{params['account']} -s #{params['server']} #{params['keychain']}`
puts output.gsub(/^password:\ "(.+?)"/,"\\1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment