Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i would like to post a notification on my NSUserDefaults but i'm not sure it's possible.

i have added the com.apple.dock preferences to my userdefaults:

Code:
-(void)awakeFromNib
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults addSuiteNamed:@"com.apple.dock"];

//then code that says if dock is on autohide, setHidden some stuff, etc.
}

but posting a notification to awakeFromNib method is pointless since it only gets called at launch, so how can i make it work so that if the dock's autohide is toggled externally (from system preferences, terminal, etc.), it will reflect in the application?

[EDIT] the reason for the problem is that the awakeFromNib code essentially set certain NSMenuItems hidden based on certain system preferences. i managed to make this work, but it's such a hack i can't believe it actually works. to install an IBAction that would send the notification, i essentially setup an invisible window (at screensaver level) under the menu bar with a tracking area, so once the mouse rolls over it, the notifications are sent and received.

there must be a more standard way of doing this, no?

[EDIT 2] strange behavior with notifications and NSLog. in my main class's init method i've registered the notifications with NSLog(@"... Notifications Registered"); in my IBAction that fires the notification i wrote NSLog ("...Sending Notification"); and the final void function that manages the notification i included NSLog(@"...Notification Received");

but when i run the program i notice that it doesn't seem to occur in the proper order. here's my output:

Code:
2008-12-04 04:41:13.505 testApp[9411:10b] ...Registered With Notification Center
2008-12-04 04:41:15.679 testApp[9411:10b] mouse entered
2008-12-04 04:41:15.680 testApp[9411:10b] ...Received Notification
2008-12-04 04:41:15.681 testApp[9411:10b] ...sending notification
2008-12-04 04:41:20.112 testApp[9411:10b] mouse Exited
2008-12-04 04:41:26.071 testApp[9411:10b] mouse entered
2008-12-04 04:41:26.071 testApp[9411:10b] ...Received Notification
2008-12-04 04:41:26.073 testApp[9411:10b] ...sending notification
2008-12-04 04:41:32.213 testApp[9411:10b] mouse Exited
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.