Re: Trouble with preferences (using "ApplescriptObjC Explored")
Re: Trouble with preferences (using "ApplescriptObjC Explored")
- Subject: Re: Trouble with preferences (using "ApplescriptObjC Explored")
- From: Shane Stanley <email@hidden>
- Date: Mon, 21 Feb 2011 12:49:15 +1100
- Thread-topic: Trouble with preferences (using "ApplescriptObjC Explored")
On 21/2/11 12:24 PM, "Laine Lee" <email@hidden> wrote:
> How do I make Shared User Defaults pass the data it now receives
> along to the variable that was getting it directly from the text field
> before?
You can't.
> Or, now that the binding that previously defined my variable is in
> use by Shared User Defaults, how do I get the text field's contents into my
> variable?
You could ask for the text field's stringValue().
>
> If I must use the code constructs rather than the binding to create my
> defaults entries, maybe I simply need help correctly applying the code from
> the chapter 20 solution to the chapter 3 example. Would you tell me how to
> add a preference that will remember the value for "theFilename" while
> keeping the existing functionality of the chapter 3 example application
> intact?
So theFilename is a string. Let's say you want to call that preference in
the property list file "myFileName" (I'm using a different name to avoid
confusion). You could then save that using:
tell current application's NSUserDefaults to set defaults to
standardUserDefaults()
tell defaults to setObject_forKey_(theFilename, "myFileName")
You would also need to register factory defaults for the same key, and
retrieve the value using objectForKey_("myFileName").
The choices are these:
* Bind your interface items to user defaults. This makes dealing with
defaults easier (no need to worry about registering factory defaults, or
reading and writing them), but you can't then use bindings to track values
in your app.
* Bind your variables to properties of interface items. You don't have to
worry about getting the values in your code, but dealing with defaults is
more complicated.
If you only have to get the value of an item, say, when a button is pressed,
the first option is usually the easier choice. But if you are binding to
something where you need the current value regardless -- say you're using it
in some calculations that continuously update what appears elsewhere -- the
latter course makes more sense. In a lot of cases, though, it's a toss-up.
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden