Receiving Workspace Notifications

Workspace notifications are posted when:

Receiving Workspace Notifications

Instead of going through the application’s default notification center as most notifications do, NSWorkspace notifications are posted to a notification center provided by the NSWorkspace object. To receive NSWorkspace notifications, your application must register an observer with the NSWorkspace notification center, returned by the notificationCenter method.

The code fragment in Listing 1 registers a method observerMethod with the NSWorkspace notification center to receive all NSWorkspace notifications:

Listing 1  Registering for workspace notifications

NSNotificationCenter *notCenter;
 
// Assume -observerMethod:(id)aNotification exists
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
           selector:@selector(observerMethod:)
           name:nil object:nil]; // Register for all notifications