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




/usr/bin/security has some rudimentary support for this.

For example, /usr/bin/security find-generic-password -a thecloud -s iTools -g
shows me my saved password with that account name and service name.


One gotcha here is that the system currently needs to put up UI to confirm access to the keychain. If the ACL for the keychain item you're accessing requires the keychain password to be entered in order to access it, and the session in which you're running is *not* a graphic (login window) session, then your access will fail. You should be able to set this up once and click "Always Allow," assuming the process running your script does not change.

AppleScript is another scripting alternative. Here's some working sample code:


tell application "Keychain Scripting"
-- look up our key
try
set myStoogeKey to first generic key of current keychain whose service is "Dewey, Cheatem & Howe"
on error
set myStoogeKey to ""
end try
-- if we found our key, delete it
if (myStoogeKey is not "") then
delete myStoogeKey
end if

-- make a new key
make new generic key with properties {name:"Curly", account:"user3", service:"Dewey, Cheatem & Howe", password:"woowoowoo"}
set myStoogeKey to the result

-- change some attributes of the key
set (name of myStoogeKey) to "Shemp"
set (account of myStoogeKey) to "user4"
set (password of myStoogeKey) to "zzzBBBBB"

end tell



hope that helps, -ken


On Dec 21, 2004, at 2:08 PM, Scott Thompson wrote:

I'm writing a script (in Ruby) and I would like that script to store and
retrieve a password from the users keychain.


Is there any command line access for creating and retrieving passwords from
the keychain? I found something called "keytool" but it looks to be related
to Java development.


Scott

_______________________________________________ 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: 
 >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.