Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Display Notification Center Alerts from command line and AppleScripts System 10.8
Using the Automator action from this recent hint, it is easy to post notifications from AppleScripts or the command line.

To set this up, simply do the following:
  1. Download and install the action.
  2. Create a new workflow in Automator containing only the Display Notification Center Alert action.
  3. In the variables section at the bottom of the workflow construction area in Automator's window, create three variables named title, subtitle, and message.
  4. Give message a default value like "Notification sent." You can leave the default values other two blank.
  5. Drag each variable to its corresponding field in the Display Notification Center Alert action.
  6. Save the workflow as Display Notification.wflow. A good place to save it is in ~/Library/Workflows (create the folder if necessary).

Now you can display a notification from the command line using the following command:
automator -D title='Title text' -D subtitle='Subtitle text' -D message='Message text' ~/Library/Workflows/'Display Notification.wflow'

To display notifications from AppleScripts, paste the following handler into your script, and call it using the form notify("Notification title", "Notification subtitle", "Notification message")

on notify(title, subtitle, message)
	if title as text is not "" then set title to " -D title=" & quoted form of (title as text)
	if subtitle as text is not "" then set subtitle to " -D subtitle=" & quoted form of (subtitle as text)
	if message as text is not "" then set message to " -D message=" & quoted form of (message as text)
	
	do shell script "automator" & title & subtitle & message & " ~/Library/Workflows/Display Notification.wflow"
end notify
    •    
  • Currently 2.95 / 5
  You rated: 1 / 5 (22 votes cast)
 
[14,662 views]  

Display Notification Center Alerts from command line and AppleScripts | 7 comments | Create New Account
Click here to return to the 'Display Notification Center Alerts from command line and AppleScripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display Notification Center Alerts from command line and AppleScripts
Authored by: tfoutz99 on Sep 04, '12 10:39:17AM
You can then make a simple bash interface (e.g. ~/bin/Notify.sh):
#!/bin/bash
automator -D title="$1" -D subtitle="$2" -D message="$3" ~/Library/Workflows/"Display Notification.workflow" > /dev/null 2>&1

make it executable (e.g. chmod u+x ~/bin/Notify.sh), and then use:
Notify.sh title subtitle message
This makes an easy replacement for growlnotify scripts. Thanks!

[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: anakin on Feb 22, '13 09:15:37AM
You can also add this as a function to your .bashrc file. The nice part about this is if you just want to fire a quick message without a title or a subtitle, you can.
function notify {
  if [ -z $1 ]; then
     echo "Usage: notify   "
     echo "Usage: notify  "
     echo "Usage: notify "
  elif [ -z $2 ]; then
     automator -D message="$1" ~/Documents/Notify.workflow > /dev/null 2>&1
  elif [ -z $3 ]; then
     automator -D title="$1" -D message="$2" ~/Documents/Notify.workflow > /dev/null 2>&1
  else
     automator -D title="$1" -D subtitle="$2" -D message="$3" ~/Documents/Notify.workflow > /dev/null 2>&1
  fi
}


[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: xyglyx on Sep 04, '12 05:31:49PM
There is also terminal-notifier.

[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: pwburnett on Sep 06, '12 04:39:36AM

Is there a way to force the notification to stay on screen until you manually close it much like a Reminder Notification in OS X does?



[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: pwburnett on Sep 06, '12 04:41:03AM

Is there a way to force the notification to stay on screen until you manually close it much like how a Reminder Notification stays on screen?



[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: gopes on Sep 08, '12 09:04:23AM

You can make them sticky, but with a caveat: *any* workflow you use in this manner will have sticky notifications. Go to System Preferences > Notifications after you've used the command line tool for the first time and you'll see "Automator Runner" in the list. Change the settings here.



[ Reply to This | # ]
Display Notification Center Alerts from command line and AppleScripts
Authored by: diggs on Nov 06, '12 10:45:19AM

When executing this from the Automater app, the notifcation retains the Automator icon. When executing via Terminal, it shows the "blank" Application icon. Is there a way to customize the icon shown, preferably via the Terminal option?



[ Reply to This | # ]