Tuesday, May 3, 2005

Conditionally call Growl from AppleScript

In this post I mentioned that I added Growl support to the Post TrackBack AppleScript.  I wanted to do this in a way that would work correctly if Growl wasn't installed.  (AppleScript has a habit of popping up a dialog if it can't find an application that it was expecting.

This page has a great example of using Growl if it is installed.

Here is the function that I am using in the script:

on display_trackback_message(messageTitle, messageBody)

tell application "System Events"

set myGrowl to "GrowlHelperApp" as string

set GrowlExists to exists application process myGrowl

end tell

if GrowlExists then

set appName to "Post Trackback Script"

set notificationName to "Trackback Notification"

set notifs to [notificationName]

tell application "GrowlHelperApp"

register as application appName all notifications notifs default notifications notifs icon of application "ecto"

end tell

using terms from application "GrowlHelperApp"

tell application "GrowlHelperApp"

notify with name notificationName application name appName title messageTitle as string description messageBody as string icon of application "ecto"

end tell

end using terms from


tell application "ecto"

display dialog messageBody buttons {"OK"} default button "OK"

end tell

end if

end display_trackback_message

Technorati Tags: