Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'd love to be able to take advantage of 10.8's Notification Center features in AppleScripts and shell scripts I write.

Is there a built-in command or a third-party library I can use from either an AppleScript or shell script?

Ideally the type and icon of the notification could be controlled, but even just the ability to trigger a basic banner with a stock icon (but custom text) would be appreciated.

share|improve this question
7  
Growl developers have announced that Growl 2.0 will have a "Notification Center" action. Because Growl notifications are scriptable, that will be a future solution for your problem as well. growl.posterous.com/… –  Gerry Jul 25 '12 at 20:27
    
@Gerry Nice, looking forward to that. Thanks! –  Nathan Greenstein Jul 25 '12 at 20:28
add comment

4 Answers

up vote 18 down vote accepted

With Mavericks, you can do this using AppleScript:

display notification "Lorem ipsum dolor sit amet" with title "Title"

That's it — literally that simple! No 3rd-party libraries or apps required.


From Terminal:

osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
share|improve this answer
    
I had no idea this existed! Thanks. –  Nathan Greenstein Dec 29 '13 at 19:23
add comment

terminal-notifier

From the README:

terminal-notifier is a command-line tool to send Mac OS X User Notifications, which are available in Mac OS X 10.8.

It is currently packaged as an application bundle, because NSUserNotification does not work from a ‘Foundation tool’. radar://11956694

This tool will be used by Kicker to show the status of commands which are executed due to filesystem changes. (v3.0.0)

Download

Prebuilt binaries, which are code-signed and ready to use, are available from the downloads section.

Usage

$ ./terminal-notifier.app/Contents/MacOS/terminal-notifier group-ID sender-name message [bundle-ID]

In order to use terminal-notifier, you have to call the binary inside the app bundle.

The first argument specifies the ‘group’ a notification belongs to. For any ‘group’ only one notification will ever be shown, replacing previously posted notifications. Examples are: the sender’s process ID to scope the notifications by a unique process, or the current working directory to scope notifications by a project.

The second and third arguments describe the notification itself and are its ‘title’ and ‘message’ respectively. For example, to communicate the sender of a notification to the user, you could specify the sender’s name as the title.

The fourth and last argument is an optional one. It specifies which application should be activated when the user clicks the notification. By default this will activate Terminal.app, to launch another application instead specify the application’s bundle identifier. For example, to launch Safari.app use: com.apple.Safari.

share|improve this answer
    
Sweet, a great library! Would love to see it updated with control over the icon and alert vs banner, but definitely useful. Thanks for the link! i.imgur.com/tsCeK.png –  Nathan Greenstein Jul 25 '12 at 20:27
2  
Great little app, I created a launcher and put in /usr/local/bin so that I can use it anywhere from a terminal etc. Launcher script: #!/bin/bash cd /Applications/terminal-notifier.app/Contents/MacOS ./terminal-notifier $* –  johanandren Jul 26 '12 at 7:13
4  
Launcher is helpful, if you change it a bit it works with quoted text with spaces: #!/bin/bash cd /Applications/terminal-notifier.app/Contents/MacOS ./terminal-notifier "$@" –  Redbeard Jul 31 '12 at 1:34
add comment

You can now do this with Growl2 (available from the App Store). Install Growl and enable "OS X Notifications" (screenshot)

enter image description here

Additionally, you'll need to install GrowlNotify for a command-line tool to send Growl notifications. You can download this tool for free on the Download page.

You can now generate Growl notifications from the command line, which will be forwarded to the Notification Center. For example:

growlnotify -n "My App" -m "Hello world"

enter image description here

Note that it currently doesn't seem possible to change the application icon.

share|improve this answer
    
Nice approach especially if growl is installed already. –  Besi Oct 25 '12 at 12:34
    
I think you might be able to use the option --icon path/to/icon.png for icons. –  Will Feb 12 at 17:37
add comment

Since Growl is not free, and terminal-notifier is not available on pre-10.8 systems, I tend to use cocoaDialog. It is free and open source, so you can probably also distribute along with your scripts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.