Default variables... again

New to ASS and strugling with the default variables…

I want to be able to enter text in a text field “DataEntry”. When the app relaunches it should then enter the previously entered text in the same text field. However, my script seems to fail on me:

property default : "test"

on will finish launching theObject
	make new default entry at end of default entries of user defaults with properties {name:"DataEntry", contents:default}
	set default to contents of default entry "DataEntry" of user defaults
	tell window of theObject
		try
			set contents of text field "DataEntry" of window "MainWindow" to default
		end try
	end tell
end will finish launching

on will quit theObject
	set contents of default entry "DataEntry" of user defaults to default
end will quit

on clicked theObject
	set contents of default entry "DataEntry" of user defaults to default
end clicked

Any help is appreciated…

If that’s all you want to do, skip the code and use Cocoa Bindings. Bind the value of the text field to a defaults key and let Cocoa take care of the glue.

Highlight your text field in Interface Builder and open the Bindings inspector. (Command-4.) Under “value”, set your model key path to something appropriate and enable the “Bind” checkbox.

Thanks but I need to do more than just this. This is just a test for me to get the basics working…

Like what? Why would Bindings not work for you?

I’d like to add that while he can (probably) cut out his glue code with bindings, he should still learn how to do it the manual way. Don’t wanna give the impression it’s not worth understanding the “hard” way. :slight_smile:

At first glance, it looks like he’s resetting the defaults entry summarily on each launch. Perhaps doing it conditionally would lead him down the road to solving the issue.