Last active
March 23, 2019 05:16
-
-
Save pdxmph/b1370eb9819c6160af30b21d1f58af67 to your computer and use it in GitHub Desktop.
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
#!/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