Thursday, July 24, 2014

#1 2012-11-08 03:04:54 pm

Dadoo
Member
Registered: 2008-01-30
Posts: 16

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!

Offline

 

#2 2012-11-08 03:16:27 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10454
Website

Re: Need help retaining selection info in AS Studio between launches

Hi,

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
applicationWillTerminate().

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

Last edited by StefanK (2012-11-08 03:17:23 pm)


regards

Stefan

Offline

 

#3 2012-11-08 03:53:17 pm

mouramartins
Member
From: Algarve
Registered: 2010-11-21
Posts: 116

Re: Need help retaining selection info in AS Studio between launches

StefanK wrote:

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
applicationWillTerminate().

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

Applescript:

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:

Applescript:

       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:

Applescript:

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

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

Offline

 

#4 2012-11-08 04:15:02 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10454
Website

Re: Need help retaining selection info in AS Studio between launches

mouramartins wrote:

You don't need handlers to read and write the prefs. It's automagic!

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


regards

Stefan

Offline

 

#5 2012-11-15 07:24:28 pm

Dadoo
Member
Registered: 2008-01-30
Posts: 16

Re: Need help retaining selection info in AS Studio between launches

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 big_smile

Kevin

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.022 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)