OK, here’s the deal. I’m writing an A.S.S. app that requires a password and I want it to store the password in the system keychain. So far I’ve managed to get the app to create it’s own keychain, store and retreive it’s password. (which you would think would be the hard part.) Here’s the problems I’m having.
I want to be able to delete the key if the user unselects the “store password” option in the application’s preferences. I know how to delete keys by index number, but I need to delete the key by name.
I also need to be able to update the password in the key if it has changed. If this isn’t do’able, I suppose I could delete the key and recreate it with the new password, but that brings us back to problem number 1.
I’ve done several hours of googling to no avail. Any help at all will be greatly appreciated.
Don’t you love it when people answer their own question. Here’s what I came up with and it seems to be working for now.
tell application "Keychain Scripting"
tell current keychain
unlock
set numkeys to count keys
repeat with thecount from 1 to numkeys
set keyname to get name of key thecount
if keyname is "The Key to Kill" then
set keytokill to thecount
end if
end repeat
delete generic key keytokill
end tell
end tell
As far as updating the password, I’m having the app delete the key and write a new one.