System Keychain

I’ve been trying to delete an entry from the system keychain, but so far I haven’t had any luck (I haven’t even been able to unlock it). If anyone has any tips it would be greatly appreciated.

This is what I have so far:

tell application "Keychain Scripting"
	tell keychain "System.keychain"
		unlock
		repeat with this_key in (get keys)
			if (get name of this_key) = "Test" then
				delete this_key
				exit repeat
			end if
		end repeat
	end tell
end tell

I think the problem is that you can only send commands to the User’s keychain from an AppleScript. When I set the current keychain to “System.keychain”

This doesn’t work for me either:

tell application "Keychain Scripting"
	launch
	tell keychain "System.keychain"
		set L to locked --> false
		unlock
		set U to locked --> still false
	end tell
end tell

but this does:


tell application "Keychain Scripting"
	launch
	tell current keychain -- normally the user keychain.
		tell (some generic key whose name is "ASPW")
			set myPW to password
		end tell
	end tell
end tell

Addendum: I just noticed that /Library/Keychains/System.keychain has read only ownership and permissions. That’s the explanation. You shouldn’t put anything in it, and you should only add and remove things from your User’s keychain.

Good catch on the permissions, I completely missed that. Unfortunately changing the file to 777 still doesn’t allow it to be modified.

I’m trying to write a script to clean up an application that writes to the system keychain, I guess I can’t via AppleScript or via the “security” command.