How to display Growl notifications from an AppleScript
Growl is a Mac OS X system add-on that allows applications that support it to display messages in a fading notification box, as spoken text, or as an email. Growl can be downloaded here, and after installation it will show up as a new System Preference.
Some supported applications include:
- Adium (display message when contact comes online / goes offline)
- Transmission (display message when torrent download completes)
- NetNewsWire (display message when new articles have been downloaded)
- Cyberduck (display message when an upload / download completes)
- CoverSutra (display message when currently playing song in iTunes changes)
- HandBrake (display message when DVD encoding completes)
- etc.
Growl notifications can be sent from AppleScripts and AppleScript-based applications, which is very useful if you’d like unobtrusive visual feedback during runtime or upon a script’s completion.
To display Growl notifications from an AppleScript, you need to make a list of all notification types the script will ever send as well as the notifications that are enabled by default, register the script with Growl as an application (as well as optionally set an icon from an image file or another application), and send the notification:
-- Check if Growl is running:
tell application "System Events"
set isRunning to ¬
(count of ¬
(every process whose name is "GrowlHelperApp")) > 0
end tell
-- Only display notifications if Growl is running:
if isRunning = true then
tell application "GrowlHelperApp"
-- Make a list of all notification types:
set the allNotificationsList to ¬
{"Notification 1", "Notification 2"}
-- Make a list of the default enabled notifications:
set the enabledNotificationsList to ¬
{"Notification 1"}
-- Register the script with Growl
-- using either "icon of application"
-- or "icon of file":
register as application ¬
"MyScript" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
-- Send a notification:
notify with name ¬
"Notification 1" title ¬
"This is the notification heading" description ¬
"This is the notification body." ¬
application name "MyScript"
end tell
end if
After you run a script like this for the first time, the application name you sent to Growl will show up in the Growl preference pane in System Preferences, where you’ll be able to enable / disable it, change the default notifications, or change message display settings.