Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to write user defaults to another defaults "suite"

How to write user defaults to another defaults "suite"
Thread Tools
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 18, 2003, 10:45 PM
 
I've written an application that interacts with the Address Book database, and as such needs to read the Address Book preferences. I've been doing this manually, but recently discovered the NSUserDefaults methods "addSuite" and "removeSuite" which allow me to use shared preference files.

I'll try that, but I'm sure it will make things a bit easier for reading the prefs.

Now I want to actually modify one of the preference settings. I figure I can get my application to execute a shell script command along the lines of:

defaults write <suite> <key> <value>

(which certainly does the job), but I'd like to use a nicer Cocoa way of doing this rather than invoking a unix shell.

Does anyone know how I should go about writing preferences to another applications preferences suite using Cocoa/Objective-C?
( Last edited by Brass; Mar 18, 2003 at 10:53 PM. )
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 19, 2003, 03:05 AM
 
Suites aren't what you're looking for. *waves hand in a Jedi-like manner* The new suite-related methods let you create and remove defaults domains that aren't tied to a particular application, but you access these domains like you would any other.

Here's what you're looking for:
Code:
NSMutableDictionary *addressBookDefaults; addressBookDefaults = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.AddressBook"] mutableCopy]; [addressBookDefaults setObject:@"us" forKey:@"ABDefaultAddressCountryCode"]; [[NSUserDefaults standardUserDefaults] setPersistentDomain:addressBookDefaults forName:@"com.apple.AddressBook"]; [addressBookDefaults release];
Substitute the specific key and value you're dealing with, of course.
Rick Roe
icons.cx | weblog
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 19, 2003, 05:02 PM
 
Rickster,

Thanks, that's exactly what I was looking for. I had seen the "persistentDomainForName" method in the documentation, but must have misinterpretted it's use as I was quickly looking through the doco.

And good guess That's exactly the key/value pair I was going to be replacing.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:18 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,