On Nov 2, 2011, at 1:47 PM, Travis Griggs wrote:

> I'm trying to create a language binding into the Cocoa environment. And my 
> current problem is how to be able to determine when NSUserDefaults values 
> have changed.

> [...] I just want to know when a user changes a value found in the 
> NSGlobalDomain. In particular at the moment, the result I read with the 
> command line expression
> 
> defaults read NSGlobalDomain AppleShowScrollBars

You can't.  There's no general means to know when other processes change 
defaults, especially in domains other than your app's.

However, there's a very good chance that System Preferences sends out a 
distributed notification when it changes that setting.  The exact name of that 
notification is an implementation detail which could change at any time and 
relying on it in a shipping application is inviting trouble.  I don't know for 
sure that there is such a notification nor what its name might, but you can 
write a program which monitors _all_ distributed notifications and find out for 
yourself.  Just watch what happens when you toggle that System Preferences 
setting.

        NSDistributedNotificationCenter* center = 
[NSDistributedNotificationCenter defaultCenter];
        [center addObserver:self selector:@selector(observeDistributed:) 
name:nil object:nil];

- (void)observeDistributed:(NSNotification*)notification
{
    NSLog(@"NSDistributedNotificationCenter: %@\n%@", [notification name], 
notification);
}

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to