I want to attach a folder action to a network mounted folder to alert me whenever someone drops a file into it. The script I have works great, as long as there is more than one file in the folder. If there is only one file, I get no notification. Anyone have any ideas what I’m doing wrong?
--on adding folder items to this_folder after receiving added_items
set icon_file to "2074:Users:admin:Desktop:ftp.png" as alias
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages" as alias
try
try
tell application "Finder"
set fileList to every file of folder FilePath as alias list
end tell
end try
repeat with aFile in fileList
tell application "Finder"
set namedFile to name of aFile as string
end tell
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Pages_Done"}
-- 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 prefpane.
set the enabledNotificationsList to ¬
{"Pages_Done"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"News Pages Finished" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application icon_file
-- Send a Notification...
notify with name ¬
"Pages_Done" title ¬
"There are finished news pages available" description ¬
namedFile & " has been placed on the FTP site" application name ¬
"News Pages Finished" image from location icon_file
end tell
end repeat
end try
--end adding folder items to
Hi,
the problem could be, that you define the folder as alias but specify it in the first Finder tell block as folder [alias].
Try blocks in a folder action event are useless. When the first error occurs, the script aborts silently.
The second Finder block is not necessary, because you can retrieve the file names directly in the first block
--on adding folder items to this_folder after receiving added_items
set icon_file to "2074:Users:admin:Desktop:ftp.png" as alias
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages:"
tell application "Finder" to set fileList to name of every file of folder FilePath
repeat with namedFile in fileList
tell application "GrowlHelperApp"
set allNotificationsList to {"Pages_Done"}
set enabledNotificationsList to {"Pages_Done"}
register as application ¬
"News Pages Finished" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application icon_file
-- Send a Notification...
notify with name ¬
"Pages_Done" title ¬
"There are finished news pages available" description ¬
namedFile & " has been placed on the FTP site" application name ¬
"News Pages Finished" image from location icon_file
end tell
end repeat
--end adding folder items to
Huh. Thanks. I’d put the try blocks in while I was troubleshooting other issues in a larger script I pulled this from. I didn’t think they would make a difference one way or the other.
In case anyone is wondering why on earth I need this, here’s the reason.
That folder is on an FTP server that I have mounted as an AFP server. I work at a newspaper, and that is where the editors (who are in another city) place zip files containing the quark files and photos for each page of the paper. I set up Growl so this application uses a different style notification and leaves it on the screen until I close it. This way, even if I’m away from the computer, or even just looking at the wrong monitor, I will be notified immediately whenever there is a page finished. That way I can get it PDFed and to our printer ASAP.
I hope it’s useful to someone else in a similar situation.
Here’s the finished code:
on adding folder items to this_folder after receiving added_items
set icon_file to "2074:Users:admin:Desktop:ftp.png" as alias
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages" as alias
tell application "Finder" to set fileList to name of every file of folder FilePath
repeat with namedFile in fileList
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Pages_Done"}
-- 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 prefpane.
set the enabledNotificationsList to ¬
{"Pages_Done"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"News Pages Finished" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application icon_file
-- Send a Notification...
notify with name ¬
"Pages_Done" title ¬
"There are finished news pages available" description ¬
namedFile & " has been placed on the FTP site" application name ¬
"News Pages Finished" image from location icon_file
end tell
end repeat
end adding folder items to
you did it again.
Either
.
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages:"
tell application "Finder" to set fileList to name of every file of folder FilePath
.
or
.
set FilePath to "FTP:Incoming:OsseoPressNews:NEWS:Finished News Pages:" as alias
tell application "Finder" to set fileList to name of every file of FilePath
.
is correct.
do you see the difference? 