Re: How do I save an array in plist?
Re: How do I save an array in plist?
- Subject: Re: How do I save an array in plist?
- From: Shane Stanley <email@hidden>
- Date: Fri, 30 Nov 2012 17:04:44 +1100
On 30/11/2012, at 5:15 PM, Brian Christmas <email@hidden> wrote:
> I'm confused!
You need to understand how user defaults work.
First, you need to use registerDefaults_ to register default values, otherwise there'll be nothing there when the app is first run or they haven't ever been changed.
No value for any key is written unless you set it to something other than the value you passed in registerDefaults_.
So the normal approach when you launch is to register the defaults, then read the values. If the file has a different value for a key, the new value will be returned, otherwise the default will be returned.
So (untested):
tell current application's NSUserDefaults to set defaults to standardUserDefaults()
tell defaults to registerDefaults_({bottomButtonChoice:3, bottomText:"Default text", saveLocalftpArchive:true, messagesTop:{theGraphClient:"Email list"}})
tell defaults
set messagesTopText to objectForKey_("messagesTop") -- returns last setting, or default value if never set
-- use messagesTopText where you want, then if you want to change the value later...
setValue_forKey_({theGraphClient:"Some other list"}, "messagesTop")
-- now when you retrieve it
set messagesTopText to objectForKey_("messagesTop") as list -- returns {theGraphClient:"Some other list"}
end tell
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden