Keychain Scripting set password

Hi
If I use the method below, it works fine if i call it with a string like setPassword(“test”). But if I call it in XCode in a text field handler it doesn work, I get an error (see below error msg). Could anybody help me?


on setPassword(newValue)
	tell application "Keychain Scripting" to set password of first generic key of current keychain whose service is "com.myService" to newValue
end setPassword

on changed theObject
	if the name of theObject is "password" then
		setPassword(contents of text field "password" of window "xxx" as string)

error msg (for typing “f” in the text field):
Keychain Scripting got an error: Can’t set password of generic key 1 of current keychain whose service of it = “com.myService” to “f”. (-10006)