Cocoa classes for having fun with Mountain Lion's Notification Center
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

ncMeta Project

by Tim Schröder (see my website, or my blog, or follow me on Twitter).

ncMeta Project is a set of classes for having fun with Mountain Lion’s Notification Center. In its present form, it offers the functionality

  • to monitor notifications being delivered to the Notification Center by any app;
  • to monitor Notification Center being invoked (and thereby brought to front) by the user.

I developed the ncMeta Project to facilitate interaction with Mountain Lion’s Notification Center beyond the limited functionality presently offered by the NSUserNotificationCenter class. The ncMeta Project doesn’t use any hacks or non-public methods.

How does it work?

The ncMeta Project consists of several classes, most of which are described below. However, you’ll typically only have to interact with the [TSNCMetaController][] class and the [TSNCMetaControllerDelegate Protocol][]. A sandboxed sample application project (ncMeta App) is available. For more information on what the sample application does, see my blog.

Behind the scenes, the ncMeta Project reads from the sqlite database Notification Center uses to store information about notifications and the apps which deliver them. To monitor when Notification Center is in front, it sets a timer and regularly checks if its window (which doesn’t look like a window) is the front-most window.


To use the ncMeta Project in your application, first

  • put all ncMeta files into your Xcode project,
  • put the fmdb classes mentioned below into your Xcode project,
  • if you want to sandbox your app, please read the [sandbox caveats][] below,
  • link to the CoreServices framework and to the libsqlite3.dylib library,
  • read the [General Caveats].

Second, read and follow the documentation of the [TSNCMetaController][] class and the [TSNCMetaControllerDelegate Protocol][]. Off you go!

General Caveats

  • ncMeta Project will only compile with Xcode 4.4+ and needs ARC to be enabled.
  • ncMeta Project uses the fmdb framework and needs the following .h and .m files to be present in order to compile: FMDatabase, FMDatabaseAdditions, FMDatabasePool, FMDatabaseQueue, FMResultSet.
  • ncMeta Project is work in progress.

Sandbox Caveats

You can run the ncMeta Project classes in a sandbox. Add the temporary entitlement key with a value of /Library/Application Support/NotificationCenter/ to your entitlements plist file, or ask the user for access to that directory via an open dialog and store the security-scoped URL you receive for later access. Though ncMeta doesn’t write to Notification Center’s database, I’ve experienced issues with the fmdb framework corrupting Notification Center’s database when having only read-only access.


The license for ncMeta Project is contained in the „“ file.

Support and so on

There is no support for ncMeta Project. For feature requests and bug reports, please use GitHub’s issue tracker. I’ll see what I can do.


TSNCMetaController is the only class you’ll have to interact with. As it provides interaction with an external ressource, the Notification Center, it has been designed as a singleton class.


Connect to the TSNCMetaController singleton using code like this:

TSNCMetaController *ncController = [TSNCMetaController sharedController];

Before using TSNCMetaController, you’ll have to set its delegate property, as most communication between the controller class and your application will be uni-directional, facilitated by the [TSNCMetaControllerDelegate Protocol][]. So, to start monitor operations after having connected to the TSNCMetaController singlton, use this code:

[ncController setDelegate:self];
[ncController startOperations];

You’ll then receive information about Notification Center events via the [TSNCMetaControllerDelegate Protocol][].

Public Methods

-(void) startOperations

Begins monitoring Notification Center’s behaviour, i.e. if it is brought to front or if new notifications are delivered to it. If one of this happens, the delegate is called via the [TSNCMetaControllerDelegate Protocol][].

-(void) stopOperations

Stops monitoring Notification Center’s behaviour. This method should be called when the app terminates.

- (void)resetCount

If invoked, resets the internal count on how many notification have been delivered to the Notification Center by apps. This method is suitable to be called after the Notification Center has become visible.

-(void) setDelegate:(id)delegate

Sets TSNCMetaController’s delegate. The delegate must conform to the [TSNCMetaControllerDelegate Protocol][].

TSNCMetaControllerDelegate Protocol

The TSNCMetaControllerDelegate Protocol is used to inform the TSNCMetaController delegate about things happening to the Notification Center.

-(void) hasBecomeVisible

This delegate method is called when the Notification Center has become visible on the user’s screen.

-(void) hasBecomeInvisible

This delegate method is called when the Notification Center has been hidden by the user.

-(void) newNotifications:(NSArray*)newNotifications

This delegate method is called when new notifications have been delivered to and by the Notification Center. The array passed contains an object of the type [TSAppRecord][] for every app which has delivered a notification.


TSAppRecord is the model class used to pass information on notifications delivered to the Notification Center by an app. It contains a number of public properties and one public method.

Public Properties

@property (strong) NSString *bundle_id

Contains the bundle id of the app which has delivered a notification to the Notification Center, e.g.

@property (assign) NSInteger show_count

Contains the maximum number of notifications that are shown in the Notification Center for the app, as set by the user in System Preferences.

@property (assign) BOOL shown

Is YES if the user has enabled Notification Center notifications for this app in System Preferences, NO if the user has disabled this behaviour.

@property (assign) NSInteger increase

Contains the number of notifications this app has delivered to the Notification Center since the last reset of this property. Calling TSNCMetaController’s -resetCount method resets this property for all TSAppRecord instances present. The value of this property may be greater than the value the show_count property returns.

Public Methods

-(NSString*) displayTitle

This convenience method returns the localized title of the application whose notification info is contained in a TSAppRecord instance.