Growl Now

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Growl Now Sat Jul 07, 2007 11:12 pm • by IDontDoWindows
Working on another user's scripts for Growl notifications via Hazel (thanks Robb!, we've now got a way for Growl notifications via Hazel for those of us using the stable version.

The first script is the main script. This checks to see if Growl is running, starting it if it isn't (assuming it can find Growl). This script also puts notifications to Growl. This is the script your other scripts will call.

Code: Select all
property ourBeloved : "Hazel"

tell application "Finder"
   -- is growl running?
   if (name of processes) contains "GrowlHelperApp" then
      -- has app been registered with growl?
      if not (exists file "Hazel.growlTicket" of folder "Tickets" of folder "Growl" of (path to application support from user domain)) then my registerGrowlApp()
   else
      -- try to start growl; if error, notify & quit
      try
         set growlFound to false
         set growlSubPath to "PreferencePanes:Growl.prefpane"
         set growlLocalPath to (path to library folder from local domain as string) & growlSubPath
         set growlUserPath to (path to library folder from user domain as string) & growlSubPath
         
         -- look for growl in computer's library and user's library
         if exists file growlLocalPath then
            set growlFound to true
            open file growlLocalPath
         end if
         if exists file growlUserPath then
            set growlFound to true
            open file growlLocalPath
         end if
         if growlFound is false then error
         
      on error errMsg number errNum
         
         -- notify user
         display dialog "Growl not found in:" & return & growlLocalPath & return & growlUserPath & return & return & "Please install Growl."
      end try
   end if
end tell

on notify(nType, nTitle, nText)
   tell application "GrowlHelperApp"
      notify with name nType title nTitle description nText application name ourBeloved
   end tell
end notify

on registerGrowlApp()
   tell application "GrowlHelperApp"
      (*
         You can add as many notifications to this list as you want. I haven't seen a need for more than one. You can set the growl to say anything you want; "Let Me Know" isn't going to appear in the growl. You might find using more than one notification if you want to set different display options for different types of notifications.
      *)
      set notificationsList to {"Tell Me Something", "Tell Me Something Else"}
      register as application ourBeloved all notifications notificationsList default notifications notificationsList icon of application "HazelHelper.app"
   end tell
end registerGrowlApp


The second script is what you tell Hazel to run. It calls and loads the first script and tells the first script what to tell Growl. You can create multiple versions of the second script to reflect the text of the message Hazel should post.

Code: Select all
on hazelProcessFile(theFile)
   set pathToScript to alias "[insert filepath here, between quotes]"
   
   set GrowlNotify to (load script file pathToScript)
   
   (*
       this tell block isn't necessary. you can delete it and stick with the generic "Item has been moved"
   *)
   tell application "Finder" to set theFileName to name of theFile as string
   
   tell GrowlNotify
      run
      -- you can change the text of the notifications here
      notify("Tell Me Something Else", "Items Moved", theFileName & " has been moved.")
   end tell
end hazelProcessFile


I know this may be confusing for newbies. Feel free to ask questions.
IDontDoWindows
 
Posts: 57
Joined: Sun Jan 07, 2007 5:43 am

Return to Tips & Tricks - DO NOT POST QUESTIONS