The error you’re getting (-1708) is an apple event error. Some event you are using is causing your problem. Perhaps you have an on awake from nib or on open event that the window or nib itself is calling that either you don’t know about, or is called incorrectly. If you take out all the code but there are still connections to it, you’ll get error for that as well.
You’re probably referencing an object that does not exist, or you have an event connecting to the script that is invalid or not supported. Make sure all of your “File Owner” and “Window” applescript connections are sound, and then clean and rebuild your project. If that doesn’t help, if you can find a way to send me your files I’d take a look.
OK, I’ve got another quick problem. I’ve got a password being saved in a preferences entry, and I want that password to be put into the password field as soon as the application launches. Here’s the code I’ve got, but it says it cannot create script command:
if default entry "iMaintain_Saved Password" exists then
if the contents of default entry named "iMaintain_Saved Password" of user defaults is equal to "" then
tell window "main"
set the contents of secure text field "PassText" to ""
end tell
else
tell window "main"
set the contents of secure text field "PassText" to the contents of default entry named "iMaintain_Saved Password" of user defaults
end tell
end if
end if
Any help would be appreciated. Also, is there a way for a text field to not be automatically selected when the application launches, so that the user can see the placeholder (and the instructions it gives)? The text field’s name is “PassText” and the window’s name is “main”. Thanks.
You cannot reference a secure text field as “secure text field”. You just call it as “text field” and it’s secure status is set in it’s info in IB. So, try…
if default entry "iMaintain_Saved Password" exists then
set SavedPassword to contents of default entry named "iMaintain_Saved Password" of user defaults
if SavedPassword is equal to "" then
tell window "main"
set contents of text field "PassText" to ""
end tell
else
tell window "main"
set contents of text field "PassText" to SavedPassword
end tell
end if
end if
You wrote…
Do you mean that the password is the first text field in the page, and you don’t want it highlited automatically when you open the window? To remove the highliting you need to set the first responder to something else in the window. There may be a way to set the first responder to a null value, but I haven’t discovered it, so you’ll need to set it to another existing object. Anyways, you could use…
on opened theObject
set first responder of window "main" to text field "uselessField" of window "main"
end opened
This assumes you add an on opened event to your window, and have a text field named “uselessField” in your window. You could also set the first responder to another object that already exists in your window, like a button or whatever. Some objects can be set as first responder that won’t be visibly highlited, like a separator line (NSBox) or an empty plain text field.