Keychain access failes

Hi everyone!

I’m currently working on a script to install a printer and enter the necessary user information into the keychain. Here is what I’ve got so far:


set keychain_entry to "HULT_Printer" --name of the Printer/ entry
set keychain_entry_user to " & userdomain & " -- Username - taken from an earlier dialog
set keychain_entry_passwort to " & printerpass & " -- User password - taken from an earlier dialog

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:"HULT Printer"}
		end try
	end tell
end setPassword

The script doesn’t return an error, but it doesn’t create an entry either :frowning:

What have I done wrong?! :slight_smile:

Thanks so much for your help!

ah, dumb…

set keychain_entry to "Hult_Printer"
set keychain_entry_user to userdomain
set keychain_entry_passwort to printerpass

tell application "Keychain Scripting"
	unlock
	tell current keychain
		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:""}
		end try
	end tell
end tell

This one works perfectly