Scripting Keychain deletion and creation

I am trying to come up with a way for helping people who have forgotten their keychain password to delete the current keychain and create a new blank one with their new password. We bind to the AD and sometimes they get out of sync and would like a quick way to delete the old and make a new.

I know how to remove the old via a shell script. But not sure what the applescript command is to create a new one.

The simplest way to do this since you already know the shell command is to create an applescript, and where you need to delete the keychain, wrap the terminal command (shell) in a do shell script… See example below:

do shell script “/usr/bin/whoami”

As you can see, the terminal command is wrapped in quotes, so if you have to use single quotes, be sure to use the backslash key. You may also want to assign a variable and wrap your shell command in a Try - End try.

Hope this helps!

Model: Mac Pro
AppleScript: Newest, of course
Browser: Firefox 3.5.7
Operating System: Mac OS X (10.6)

Maybe this helps. Needs some adaption.

set keychain_entry to "somekey" --  customize this
set keychain_entry_user to system attribute "USER"
set keychain_entry_passwort to "secret" --  customize this



on setPassword(new_Password)
	tell application "Keychain Scripting"
		unlock
		try
			set password of first generic key of current keychain whose name is keychain_entry to keychain_entry_passwort
		on error
			make new generic key with properties {name:keychain_entry, account:keychain_entry_user, password:keychain_entry_passwort, comment:"bla bla"}
		end try
	end tell
end setPassword