Hacking notification center

When Apple released OS X 10.7, Mountain Lion, in 2012, one of the (literal) banner features was Notification Center, a column added to the right hand side of the Mac’s screen on which all manner of alerts and other info from various applications could be found.

Originally an iOS feature, it hasn’t really found many fans among OS X users.

But it doesn’t have to be that way. With a little tweaking you can use Notification Center like a sort of cork board, on which you pin notes to yourself. Notes that can activate applications, open URLs and more.

For this tutorial we’re going to be using the Terminal to create these notes to yourself, but next time we’ll show you how to write a standalone application using Automator to put a nice graphical gloss on the whole thing. It’s best to start off with some understanding of what’s going on though.

So to start, open the Terminal. It’s in Applications > Utilities, or of course you can just activate Spotlight and type the first few letters to launch it quickly. Next, you’ll need to install a small utility called Terminal Notifier. To do this, type:

sudo gem install terminal-notifier

InstallationHit return and then you’ll be asked for your admin password. A few seconds later, you should be told that the software has successfully installed.

To make your first notification, type:

terminal-notifier -message “I am very clever”

and hit return.

You’ll see your notification appear as a banner, and then disappear.

If you open Notification Center by tapping on its icon in the upper-right corner of the screen, you’ll find your message among the notifications from terminal-notifier, since all notifications are sorted according to the application that sent them.

My First NotificationTo save yourself a lot of scrolling, you might like to open the Notifications pane of System Preferences and sort the order in which applications’ notifications appear. Put terminal-notifier at the top of the list.

Alternatively, you can fool the Mac into thinking that a notification has come from a different application. To do that, you simply type:

terminal-notifier -message “Open Safari” -sender com.apple.Safari

and hit return.

Brilliant disguiseThen a notification will appear in Notification Center sorted as if it came from Safari, complete with a Safari icon. If you click on it, Safari will open. The same is true for any application that you fake in this way.

You could, for instance, send yourself

terminal-notifier -message “DEADLINE APPROACHING” -sender com.apple.Pages

to remind yourself to get on with some writing you need to get done.

(Note that the value of -sender has to be the ID of the application, not merely its name. For most Apple applications, this will be com.apple.Applicationname, but the same is not necessarily true for all developers’ applications. It’s not even true for all Apple applications — for instance Contacts is com.apple.AddressBook. Good luck.)

Of course opening Safari when you click a notification has limited utility. Generally speaking, when you open Safari it’s because you want to look at a URL. There is a way to do that as well.

Type

terminal-notifier -message “Check this out” -open “http://apcmag.com”

and hit return.

Notification Center PrefsOnly the message text will be visible, but when you click on the notification it will open Safari (or your default browser) and load up the specified URL.

Unfortunately, the -open variable will only work if the sender of the notification is Terminal Notifier, so it doesn’t work if you’ve faked the sender using -sender. Sorry.

There are other ways to pretty up your notifications, though, even if they do have a boring Terminal icon on them.

For instance, type

terminal-notifier -title "?" -subtitle "Stay cool" -message "If a puppy can do it you can" -open "https://www.youtube.com/watch?v=GIHiuAzBXEg"

and hit return.

My NotificationsAll going well you should hear a noise, then when you click on the notification you should see an entertaining video of a puppy trying to climb into a refrigerator.

And yes, that’s an emoji. It’s a simple enough way to dress up an otherwise dull-looking notification.

Hopefully by now you’re starting to see some of the uses that sending yourself notifications can be put to. You’ll also notice that it’s all a bit geeky and command-liney, which is why next time we’ll build an application using Automator that will stop you having to open the Terminal.

Make Notifications stick around

When you receive a notification in OS X, it doesn’t stick around long — five seconds, actually. Sometimes, though, you want them to stay longer than that, or even indefinitely.

To change the default time that notifications spend on screen, open the terminal and type

defaults write com.apple.notificationcenterui bannerTime 30

and hit return. Then type

killall NotificationCenter

and hit return.

That will quit Notification Center and force it to reload with the new default.

Once you’ve done this, banners will stick around for 30 seconds. Obviously, adjust that 30 to whatever number of seconds you want.

If you want notifications to stick around until you click on them, open the Terminal and type

defaults write com.apple.notificationcenterui bannerTime 86400

Then hit return, and repeat the steps above to Force Notification Centre to quit and reload its new default.

Then, any notification you send yourself (as well as all others) will hang about until you click on them. Warning: that can get crowded.

Make Notification Center shut up

Do Not DisturbOK, so we’ve had lots of fun sending ourselves notifications and making them stay on screen as long as we want, but what about when there’s work to be done?

Enter Do Not Disturb, the best thing Apple ever added to Notification Center. You can activate Do Not Disturb by going into System Preferences, opening the Notifications pane and clicking on Do Not Disturb at the top of the applications list.

Or you can simply hold down the option key and click on the Notification Center icon in the top-right corner of the screen.

Bliss.

  • . It‘s ideal to start off with some understanding of what’s going on
    even though.