Created
August 22, 2012 14:43
-
-
Save sunny/3426280 to your computer and use it in GitHub Desktop.
ActionScript Folder action to send Growl notifications on new items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
add - new item alert | |
This Folder Action handler is triggered whenever items are added to the attached folder. | |
The script will display an alert containing the number of items added and offering the user | |
the option to reveal the added items in Finder. | |
Copyright © 2002–2007 Apple Inc. | |
You may incorporate this Apple sample code into your program(s) without | |
restriction. This Apple sample code has been provided "AS IS" and the | |
responsibility for its operation is yours. You are not permitted to | |
redistribute this Apple sample code as "Apple sample code" after having | |
made changes. If you're going to redistribute the code, we require | |
that you make it clear that the code was descended from Apple sample | |
code, but that you've made changes. | |
*) | |
on adding folder items to this_folder after receiving added_items | |
-- Get the name of the folder | |
tell application "Finder" | |
set the folder_name to the name of this_folder | |
end tell | |
-- Find out how many new items have been placed in the folder | |
set the item_count to the number of items in the added_items | |
-- Create the alert string | |
if the item_count is greater than 1 then | |
set alert_message to (the item_count as text) & " new items have " | |
else | |
set alert_message to "One new item has " | |
end if | |
set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "." | |
-- Register Growl | |
tell application "System Events" | |
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0 | |
end tell | |
if isRunning then | |
tell application id "com.Growl.GrowlHelperApp" | |
-- Make a list of all the notification types | |
-- that this script will ever send: | |
set the allNotificationsList to ¬ | |
{"New item"} | |
-- Make a list of the notifications | |
-- that will be enabled by default. | |
-- Those not enabled by default can be enabled later | |
-- in the 'Applications' tab of the Growl preferences. | |
set the enabledNotificationsList to ¬ | |
{"New item"} | |
-- Register our script with growl. | |
-- You can optionally (as here) set a default icon | |
-- for this script's notifications. | |
register as application ¬ | |
"New item in folder" all notifications allNotificationsList ¬ | |
default notifications enabledNotificationsList ¬ | |
icon of application "Finder" | |
notify with name ¬ | |
"New item" title ¬ | |
"New item" description ¬ | |
alert_message application name "New item in folder" | |
end tell | |
end if | |
end adding folder items to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment