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.
#!/bin/bash
/usr/bin/osascript -e "display notification \"$*\""
Now to display a notification:
notify Lorem ipsum dolor sit amet
sleep 5; notify Slow command finished
Growl 2.1 does support ScriptActions, but it doesn't seem to be documented anywhere but a google group thread. Below is a simple example from the thread. You create a script file with the content, place it in ~/Library/Application Scripts/com.Growl.GrowlHelperApp
, and then set it up inside Growl as described in the same thread.
using terms from application "Growl"
on perform action with notification
ignoring case
if notification's app name is "test growl" then
activate me
display dialog "goodbye" with icon 1
end if
end ignoring
end perform action
end using terms from
Best Answer
Growl has an AppleScript dictionary. I didn't find any way to show a single notification in Notification Center, but they are shown in it by default you've enabled forwarding all notifications.