Hi all,

On osx, I'm developing a small library hosted on rubyforge [1]. A
rakefile task takes care of  automatizing the release process.

The code snippet shown here allows the login information (username and
password) to be retrieved from osx's keychain [2]:

def keychain_login(domain)
  info = `security find-internet-password  -s '#{domain}' -g 2>&1`.split("\n")
  username = info.grep(/^\s*\"acct\"\<blob\>=\"(.*)\"$/){$1}.first
  password = info.grep(/^password: "(.*)"$/){$1}.first
  [username, password]
end

keychain_login('rubyforge.org')

This way, the username and password don't have to be hardcoded in the
script nor typed at run-time, nor set in the environment.

I hope this can make life slightly easier for my fellow developers on osx.

Ciao
Stefano


[1] http://intervals.rubyforge.org/
[2] To have your username/password stored in the keychain, use Safari
to login on rubyforge at least once.