Skip to content

Instantly share code, notes, and snippets.

@jpmckinney
Created November 9, 2010 02:56
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jpmckinney/668628 to your computer and use it in GitHub Desktop.
Access the OS X Keychain from Ruby
# blog post: http://blog.slashpoundbang.com/post/1521530410/accessing-the-os-x-keychain-from-ruby
class KeyChain
def self.method_missing(meth, *args)
run args.unshift(meth)
end
def self.find_internet_password(*args)
# -g: Display the password for the item found
output = quiet args.unshift('find-internet-password', '-g')
output[/^password: "(.*)"$/, 1]
end
private
def self.run(*args)
`security #{args.join(' ')}`
end
def self.quiet(*args)
run args.unshift('2>&1 >/dev/null')
end
end
@scrogson
Copy link

-w Display only the password on stdout

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