Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command line access to keychain



> Thanks.  This appears to work OK for displaying items from the command line.
> Unfortunately it always sends it's output to stderr which makes it harder to
> catch the output and extract the actual password text from it.  Grrrr.
> 
> AppleScript may be a workable alternative as it looks like it might be
> easier to get ahold of the actual password text.
>

For the posterity of the ages, here is the ruby code I used to extract the
password.  Comments or corrections are welcome... But this seems to work:

def findPassword
    retVal = nil;

    myin, myout, myerr = Open3.popen3('security find-generic-password -g -s
"PasswordNeeded"')
    myin.close
    myout.close
    myerr.each_line do | fishline |
        if fishline =~ /password:[ \t]+\"(.*)\"/ then
            retVal = $1
        end
    end

    return retVal
end

I replace PasswordNeeded with whatever password key you like.
Sent using the Microsoft Entourage 2004 for Mac Test Drive.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Apple-cdsa mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/apple-cdsa/email@hidden

This email sent to email@hidden

References: 
 >Re: Command line access to keychain (From: "Scott Thompson" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.