How to listen to all possible notifications in 7 lines of code

14
Nov
2

In the last post I mentioned about setting the background to your dragged image and sending the appropriate [private] notification so that Mac OS X would actually change it. At first it didn’t work so I thought that this notification is no longer valid (considering the fact that it’s private). So I’ve setup a little app for myself which listens to all possible notifications while run.

Main snippet that does all the job is put in 7 lines of code:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
  [dnc addObserver:self selector:@selector(processNotification:) name:nil object:nil];
}
 
- (void)processNotification:(id)notification {
  NSLog(@"Notification: %@", notification);
}

So here’s another idea for another developer tool. Maybe there’s one that already exists, but it’d be really cool to have an app that registers all your your wanted notifications (either by name, app or any other parameter).

Enjoy this article?

Consider subscribing to our RSS feed!

2 Comments

  1. cocoa
    00:16 on January 13th, 2010

    notificationwatcher is the holy grail for quite some time

  2. eimantas
    09:59 on January 13th, 2010

    Thanks! Looks really nice .)

Leave a comment

RSS feed for comments on this post