Topic: Growl-enabled folder action broken under

The Growl forums have moved to Google Groups, this forum is read only.
Locked
sidesh0w
Harmless
Posts: 4
Joined: Fri May 06, 2005 5:17 am

Topic: Growl-enabled folder action broken under

Post by sidesh0w »

I wrote a little folder action to alert me via Growl when files have been dropped into the folder, but for some reason my script flat-out fails under Tiger. Here 'tis:

Code: Select all

on adding folder items to this_folder after receiving newitems
   
   set total to the count of newitems
   -- Yes, I'm a grammar whore. Sue me.
   if total is greater than 1 then
      set item_title to "New Items!"
      set item_num to " items have"
   else
      set item_title to "New Item!"
      set item_num to " item has"
   end if

   tell application "Finder"
      -- Get the name of the folder
      set the folder_name to the name of this_folder
   end tell
   
   tell application "GrowlHelperApp"
      -- Send message to Growl
      notify title ¬
         item_title description ¬
         (total as string) & item_num & " been dropped in the " & folder_name & " folder." icon of application "Finder"
   end tell
   
   tell application "Finder"
      -- Open the folder
      activate
      reveal newitems
   end tell
   
end adding folder items to


I suck at AppleScript, so it's probably my hackneyed code--but do any Growl samurais out there see what I might be doing wrong?
sidesh0w
Harmless
Posts: 4
Joined: Fri May 06, 2005 5:17 am

Post by sidesh0w »

If it helps with the diagnosis at all, rewriting the script to:

Code: Select all

on adding folder items to this_folder after receiving newitems
   try
      set total to the count of newitems
      
      -- Get the name of the folder
      tell application "Finder"
         set the folder_name to the name of this_folder
         activate
         reveal newitems
      end tell
      
      tell application "GrowlHelperApp"
         set the allNotificationsList to {"New Item Notification"}
         
         set the enabledNotificationsList to {"New Item Notification"}
         
         register as application ¬
            "New Items Script" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "Script Editor"
         
         -- Build the message (Yes, I'm a grammar whore. Sue me.)
         if total is greater than 1 then
            set item_title to "New Items!"
            set message to (total as string) & " items have"
         else
            set item_title to "New Item!"
            set message to (total as string) & " item has"
         end if
         set message to message & " been dropped in the " & folder_name & " folder."
         
         -- Send message to Growl
         notify with name ¬
            "New Item Notification" title item_title ¬
            description message ¬
            icon of application "Finder"
      end tell
   end try
end adding folder items to


doesn't do the trick, either. It nets me a Finder window with the new items selected, but Growl still refuses to do anything.

Also, other notifications (Adium, Mail) work just fine. So I'm guessing this is *ahem* user error.

:)
User avatar
Diggory
Growl Team
Posts: 129
Joined: Sat Dec 04, 2004 12:17 pm
Location: London

Post by Diggory »

You need to register the script with growl.

http://growl.info/documentation/applescript-support.php
sidesh0w
Harmless
Posts: 4
Joined: Fri May 06, 2005 5:17 am

Post by sidesh0w »

Diggory, thanks so much for getting back to me; I really appreciate it.

You need to register the script with growl.


This is probably where my crappy AppleScript skills are hurting me; isn't that what this section is for?

Code: Select all

         set the allNotificationsList to {"New Item Notification"}
         
         set the enabledNotificationsList to {"New Item Notification"}
         
         register as application ¬
            "New Items Script" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "Script Editor"


The script's showing up in Growl's "Applications" pane, so presumably I'm doing *something* right...?

Thanks again, Diggory. I really appreciate it!
User avatar
Diggory
Growl Team
Posts: 129
Joined: Sat Dec 04, 2004 12:17 pm
Location: London

Post by Diggory »

My apologies - I speed read the first script - didn't notice the change in the second.

It looks like in your notify command you are forgetting to use the name of the app that you registered with:

Code: Select all

notify
  with name (string) : name of the notification to display
  title (string) : title of the notification to display
  description (string) : full text of the notification to display
  application name (string) : name of the application posting the notification.


All these parameters are not optional - so your notify section should read as follows:

Code: Select all


         -- Send message to Growl
         notify with name ¬
            "New Item Notification" title item_title ¬
            description message ¬
            icon of application "Finder"
application name "New Items Script"
sidesh0w
Harmless
Posts: 4
Joined: Fri May 06, 2005 5:17 am

Post by sidesh0w »

Diggory, you rock. That fixed it--thanks so much!
Locked