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

else

tell application "ecto"

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

end tell

end if

end display_trackback_message


Technorati Tags:

No comments:

Post a Comment

Unlocking Seamless Integration: Navigating Unexpected Hubitat Device Queries and VLAN Challenges for a Smoother Home Automation Experience

During my network debugging efforts , I came across an intriguing observation related to the two Hubitat devices on our network. The logs b...