Keychain problem

In hopes of making a search script for finding keys in the keychain, I studied the Keychain Scripting Dictionary as well as the brief example in Matt Neuburg’s text, AppleScript The Definitive Guide.

My main keychain, “holbrook” has a bazillion entries, and I ran Keychain First Aid on it. It is UNlocked.

Here is my code"


tell application "Keychain Scripting"
      launch
	set k to (get key 1 of keychain "holbrook")
end tell

and I get


get key 1 of keychain "holbrook"
		"Keychain Scripting got an error: Can't get key 1 of keychain "holbrook"."

Also, it seems to think there are no keys in this keychain (events log):


tell application "Keychain Scripting"
      launch
	get every key of keychain "holbrook"
		{}
end tell

Anybody have experience using this app? I must be missing something… TIA

On my machine (Jaguar), it appear that you cannot get properties of keys as a whole but you can get them individually. Also noteworthy is that it appears that Keychain Scripting is case sensitive (at least in some cases - no pun intended).

tell application "Keychain Scripting"
	tell keychain "holbrook"
		tell key 1
			set acct to account
			set pwd to password
			set desc to description
			set comm to comment
			set inv to invisible
			set neg to negative
			set c_date to creation date
			set m_date to modification date
			set serv to service
		end tell
	end tell
end tell

Whose clauses also work.

tell application "Keychain Scripting"
	tell keychain "holbrook"
		set matches to keys whose name is "Safari Forms AutoFill"
		repeat with match in matches
			tell me to display dialog (get account of match)
		end repeat
	end tell
end tell

This also works, returning a list of references to all keys in the keychain.

tell application "Keychain Scripting"
	tell keychain "holbrook"
		set keys_ to keys
	end tell
end tell

– Rob

OK I rebooted into a pristine Panther partition I keep around. Everything works perfectly. There is a keychain named "Login: which I did not have on the other partition. So I think my keychain is torqued up even though it passes the Keychain First Aid test.

I tried copying all the keys and pasting them into a new keychain, but you have to authenticate every one and the pasting bombed out with an error after the first 50 or so.

Anybody know how to export keys from a (presumably corrupt) keychain?

Thank you Rob. I still can’t get the “whose” construct to work unless the “name is” is used. IOW, “name contains” causes an Applescript error. Could you try this for me and see if the problem is that Keychain Scripting just does not support the “contains” or “begins with” constructs?

I got a working app by getting all the keys and then iterating through the list looking for names containing the entered string, but this takes forever.

What I want to do is have the user enter a string and the script returns all the keys that have that string in their name, along with the account and the password.