I have a folder action that notifies me through Growl when someone places a file in a certain network folder. It works great, except that if I don’t retrieve the files right away, I get repeat notifications whenever new files are added. For instance, I will get a notification for file1, then file1 & file2, then file1, file2 & file3 all piling up the side of my screen. So I thought “A-Ha! I’ll define the files that have already sent notifications in a global property list! Then it will remember between executions what files have produced notifications.” And that’s great. I get one notification per file… unless it happens to have the same name as a file that’s already had a notification. Then I get nothing. And unfortunately, there are a lot of duplicate file names, which is something I can do nothing to change.
So really I’m asking for ideas from the pros. How would you go about making sure each file gets exactly 1 notification? Here is my code:
property whiteList : {}
on adding folder items to this_folder after receiving added_items
set icon_file to "2074:Users:admin:Desktop:location-ftp-icon.png" as alias
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages" as alias
set curTime to time string of (current date)
tell application "Finder" to set fileList to name of every file of folder FilePath
tell application "GrowlHelperApp"
set the allNotificationsList to {"Pages_Done"}
set the enabledNotificationsList to {"Pages_Done"}
register as application ¬
"News Pages Finished" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application icon_file
end tell
repeat with namedFile in fileList
if namedFile is not in whiteList then
tell application "GrowlHelperApp"
-- Send a Notification...
notify with name ¬
"Pages_Done" title ¬
curTime description ¬
namedFile & " has been placed on the FTP site" application name ¬
"News Pages Finished" image from location icon_file
end tell
set namedFile to namedFile as text
set end of whiteList to namedFile
end if
end repeat
end adding folder items to
Model: PM G5 Dual 2.0
AppleScript: 1.10.7
Browser: Firefox 3.6.9
Operating System: Mac OS X (10.4)