Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 226 down vote accepted

With Mavericks and later, you can do this using AppleScript's 'display notification':

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


That's it—literally that simple! No 3rd-party libraries or apps required and is completely portable for use on other systems. 10.9 notification on the top, 10.10 DP in the middle, 10.10 on the bottom.

AppleScript can be run from the shell using /usr/bin/osascript:

osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'

You can also customise the alert further by adding…

  • a subtitle

    Append 'subtitle' followed by the string or variable containing the subtitle.

    display notification "message" with title "title" subtitle "subtitle"

    The above example produces the following notification:

  • sound

    Append 'sound name' followed by the name of a sound that will be played along with the notification.

    display notification "message" sound name "Sound Name"

    Valid sound names are the names of sounds located in…

    • ~/Library/Sounds
    • /System/Library/Sounds

Posting notifications can be wrapped as a command-line script. The following code can be run in Terminal and will add a script to /usr/local/bin (must exist, add to $PATH) called notify.

cd /usr/local/bin && echo -e "#!/bin/bash\n/usr/bin/osascript -e \"display notification \\\"\$*\\\"\"" > notify && chmod +x notify;cd -

This is the script that the above will add to notify.

/usr/bin/osascript -e "display notification \"$*\""

Now to display a notification:

notify Lorem ipsum dolor sit amet
sleep 5; notify Slow command finished
share|improve this answer
@ceilingcat This is AppleScript. To run it in Terminal, use osascript (see answer). – grgarside May 2 '14 at 18:32
The only problem with display notification is that when you click on it, the open file dialog appears. – ɹoƃı Aug 13 '14 at 20:57
Is it possible to make the notificatiop popup exist forever (not auto-hide after N seconds) until explicitly clicked by the user? – Sridhar Ratnakumar Apr 1 '15 at 22:15
Ladies and gentlemen, after an hour of investigation on the world wide web, I have found out how to let the notification window stay until dismissed by user! It was actually controlled by a setting in System Preference, rather than some parameter in the script written. These two images should explain it all Have fun guys, and thanks @grgarside for the great answer. – Vic Jang Nov 7 '15 at 0:31
Note that the text has to be in double quotes. Single quotes don't work. So if you need a variable in the text, you cannot write "display ... '$mytext' ...", but need escaped double quotes: "display notification \"$mytext\" ...". – mivk Dec 12 '15 at 11:14
up vote 60 down vote


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)


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


$ ./ 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, to launch another application instead specify the application’s bundle identifier. For example, to launch use:

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! – Nathan Greenstein Jul 25 '12 at 20:27
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 $* – johanandren Jul 26 '12 at 7:13
Launcher is helpful, if you change it a bit it works with quoted text with spaces: #!/bin/bash cd /Applications/ ./terminal-notifier "$@" – Redbeard Jul 31 '12 at 1:34

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 '14 at 17:37

I just want to add a note to @grgarside's answer, because I know many people want to have a notification popup that can only be dismissed by button click.


I have found the solution for you:

It was actually controlled by a setting in System Preference, rather than some parameter in the script written. These two images should explain it all

Thanks @grgarside for the great answer.

System Preference

share|improve this answer
Note that the specific app will vary. Script Editor is only for Script and osascript. In a service workflow, it's Automator Runner. When inside, it's Automator. – cde Mar 22 at 19:29
I find it annoying that if I click on the Banner, it brings up the Script Editor application. I'd like for it to just disappear on click, but this post points out you can hover over it and trackpad-swipe right to make it go away quietly:… – Joshua Goldberg Mar 31 at 14:24
@JoshuaGoldberg Thanks for adding that! I found that out intuitively one day, which is one thing I like about Mac OS X, it works the way you expect it do work :) – Vic Jang Apr 1 at 7:46

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.

If you don't need a lot of customization, you can also use AppleScript's display notification which you can also call from the shell as others have already mentioned.

But beware that AppleScript seems to require double-quotes. So if you need variables, this will not work:

osascript -e "display notification '$text' with title '$title'" #WRONG

You will have to use escaped double-quotes. This is ugly but works:

osascript -e "display notification \"$text\" with title \"$title\""
share|improve this answer

I recently forked terminal-notifier to build a command line tool to display notification Alerts (with actions) and Reply Type Alerts.

I use it with my shell scripts and golang apps to get interactive answers from users.

enter image description here

share|improve this answer

@grgarside's solution is nice, but it is vulnerable to script injection, which can be a major security issue when this is used to e.g. display log file contents or something similar.

This should be safer as it escapes double quotes:

/usr/bin/osascript -e "display notification \"${*//\"/\\\"}\""
share|improve this answer
this is interesting, but can you describe a scenario where a script I run on my system that is only user-executable is vulnerable to script injection? – iconoclast Dec 18 '15 at 15:49
If you display user content that is not from you, you are vulnerable. For example if you run this on a system with a public web server, or when some app logs strings it got from the net which you read and display, e.g. a browser, mail program or a Twitter client. It could have a " to end the string and statement, then have code and then restart a string. – Archimedix Dec 18 '15 at 21:54
okay, that's true. it's just hard for me to imagine ever putting content from web forms into my notifications, but your point is taken. – iconoclast Dec 18 '15 at 23:30
Well, maybe you'd just like to say something like I have a "laser" without being told you're having a syntax error by "quoting" your "words". With escaping, you can: script 'I have a "laser"' – Archimedix Dec 19 '15 at 8:47
Upvote because it's always good to keep security in mind. Someone could copy-pasta solutions and use them in ways the person posting the solution hadn't considered. – Edward Falk Jul 22 at 19:06

Here's a cool one that I use in a ruby script on OS X (so that I can start a script and get an update even after toggling away from the window):

cmd = %Q|osascript -e 'display notification "Server was reset" with title "Posted Update"'|
system ( cmd )
share|improve this answer
wow... so the chain is something like User -> Ruby -> Shell -> AppleScript -> Objective-C -> Assembly -> CPU? – iconoclast Dec 18 '15 at 15:52

Your Answer


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.