Need help retaining selection info in AS Studio between launches

Note: I accidentally originally posted this in the AppleScript OS X forum; I am reposting in the appropriate forum here:

About three years ago, I wrote an app using AppleScript and XCode 3.2 that helps our company’s designers “claim” images in Extensis Portfolio. A designer selects images from a Portfolio catalog, then enters information in three fields contained in an Interface Builder window. The app then enters that information in the appropriate fields in each selected Portfolio record, which streamlines data entry and ensures that all information is entered in the appropriate format.

Now I’ve been asked to make the app retain the information a designer enters. If a designer is claiming several different images for the same publication, they don’t want to re-enter all of the claiming information each time. The designer needs the freedom to select additional images in Portfolio and then rerun the claiming script, but of course relaunching the script currently forces them to re-enter all of the claiming information.

I thought properties would be the key, but eventually learned that they don’t fill this role in AS Studio. I’ve looked at bindings, but haven’t got a handle on how to successfully implement that technique in this scenario. I really enjoy working in AppleScript but I’m still a newbie to much of this. I’m hoping that someone here can offer some suggestions or code examples that can help me make sense of the best way to accomplish retaining information from one app launch to the next, perhaps auto-entering that info into the Interface Builder window from launch to launch. Thanks!


user defaults is the standard way to save/restore values and UI states.

First you have to register the keys (of type string, number, date, data, list and record) you want to save.
Then you need two handlers to read and write the preferences, normally in applicationWillFinshLaunching() and

There are a few articles regarding this issue in the unScripted and AppleScript Studio section

You don’t need handlers to read and write the prefs. It’s automagic!
although you can do

on will quit theObject
	call method "synchronize" of user defaults
end will quit

to be safe

You still need to register your keys as said above, normally in applicationWillFinshLaunching:

		tell user defaults
			make new default entry at end of default entries with properties {name:"myMeaningfulVar", content:"Pop"}
	-- make new does not change the contents if they exist

in the bindings inspector of Interface Builder, after secting the desired field:
controller key: “values”
model key path: “myMeaningfulVar”

It’s even an easier way to get the values of fields anytime:

	tell user defaults
		tell default entry "myMeaningfulVar"
			get contents
		end tell

will give you the content of the field even after the window is long gone.

Right, but it depends on the preference strategy.
If you need a value also as property for key-value coding relationships
it might be more comfortable to read/write the value “manually” and bind the UI element to the property

StefanK and mouramartins, thanks so much to both of you for your responses. Because of the information shared in these forums, I was able to tweak my AS Studio project so that it now retains key information from one launch to the next. The designers who use the app are very pleased!

Thanks again :smiley: