Custom AppleScript Folder Action (Growl Notification)

The Growl forums have moved to Google Groups, this forum is read only.
groomsy
Harmless
Posts: 3
Joined: Tue Nov 18, 2008 1:22 am

Custom AppleScript Folder Action (Growl Notification)

Postby groomsy » Tue Nov 18, 2008 1:28 am

So what I want to do is create an AppleScript to run as a folder action to create a Growl Notification (basically display a notification when a file is placed into my Public folder) which I was able to do and here is my code for that:

Code: Select all

on adding folder items to this_folder after receiving added_items
   try
      set notification to ""
      set fileList to ("") as Unicode text
      set notifyTitle to ("") as Unicode text
      
      tell application "Finder"
         --get the name of the folder
         set the folder_name to the name of this_folder
      end tell
      set the item_count to the number of items in the added_items
      repeat with thisFile in added_items
         tell application "Finder"
            --get the name of the folder
            set the file_name to the name of thisFile
         end tell
         if the fileList is "" then
            set the fileList to the fileList & file_name
         else
            set the fileList to the fileList & ", " & file_name
         end if
      end repeat
      if the item_count is 1 then
         set notifyTitle to "New Item in " & the folder_name & " folder"
         set notification to fileList & " has been added to " & the folder_name & " folder."
      else
         set notifyTitle to "New Items in " & the folder_name & " folder"
         set notification to fileList & " have been added to " & the folder_name & " folder."
      end if
      
      
      tell application "System Events"
         if (application processes whose name is "GrowlHelperApp") is not {} then
            tell application "GrowlHelperApp"
               register as application ¬
                  "Folder Actions" all notifications {"Added File"} ¬
                  default notifications {"Added File"} ¬
                  icon of application "Finder"
               
               notify with name "Added File" title notifyTitle description notification application name "Folder Actions" icon of file this_folder with sticky
            end tell
         end if
      end tell
      
   end try
end adding folder items to


Now I want to take this one step further: When I click on this notification, I'd like to open that folder in Finder so that I can go straight to that folder and see what was placed there. I know there is AppleScript available to open Finder to a certain folder and I know that within Adium, you can click on a Growl notification when you receive a new message and it'll bring you to that chat window (i.e. bring it to the front). So is there a way to do this? If you don't understand the question, let me know and I'll try to clarify. Thanks.

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

Re: Custom AppleScript Folder Action (Growl Notification)

Postby Diggory » Wed Nov 19, 2008 12:17 pm

The AppleScript interface doesn't do callbacks. So sorry, this isn't possible.

groomsy
Harmless
Posts: 3
Joined: Tue Nov 18, 2008 1:22 am

Re: Custom AppleScript Folder Action (Growl Notification)

Postby groomsy » Thu Nov 20, 2008 2:05 am

So how does Adium do it then? Like if you have a notification on a message, and you click on that notification, it focuses on the chat window. So just out of curiosity, how does Adium do it then? Do they use a special call system to access Growl?

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

Re: Custom AppleScript Folder Action (Growl Notification)

Postby Diggory » Thu Nov 20, 2008 2:59 am

Adium uses the Objective-C interface to Growl which allows callbacks.

The AppleScript interface doesn't support them.

groomsy
Harmless
Posts: 3
Joined: Tue Nov 18, 2008 1:22 am

Re: Custom AppleScript Folder Action (Growl Notification)

Postby groomsy » Thu Nov 20, 2008 4:50 am

Ah. Thank you for response (even if it was bad news for me).

mobdoc
Harmless
Posts: 4
Joined: Thu May 07, 2009 10:16 pm

Re: Custom AppleScript Folder Action (Growl Notification)

Postby mobdoc » Fri May 08, 2009 9:31 am

Can anyone give me a hand with Applescript/Growl/email notifications.
I'm new to Applescript and trying to design one that will send an email notification to a designated email address (along with a growl notification) as soon as a file is uploaded to my public folder on Mobile me. I accept digital medical images from clients but I never know when these are added to my public folder. Would it be possible to also automatically transfer the files from the public folder (once they are fully uploaded- often 20-50mb) to a different folder on my Mac?

As I'm new at this, I'd appreciate any help with Applescript, or even some advice on how/where to learn applescript.

-S


Return to “Growl”

Who is online

Users browsing this forum: No registered users