Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Folder action kicks in too early

I have a little applescript that is to add all files that are added to a specific folder to an iTunes playlist.

I added the script as a folder action to the folder.
It seems to work fine with single files.

However, when I copy several files (which takes a few seconds), then the script gets started too early, i.e., when only half of the files have been copied over. Consequently, only some of the files get added to the playlist.

In addition, when I copy a large number of files, it doesn't seem to work at all.

Any ideas what's wrong? or what I can do?
(Is this a bug in Mac OS? I read about an issue in 10.5 where folder actions got started before a single files was finished copying, but I haven't seen of any hints about my problem.)

Any kind of help will be highly appreciated.

Best regards,
Gabriel.

PS:
Here is my script, for completeness


(*
Automatically add the files that are dropped on this applescript to
playlist named below.
To adapt it for a different playlist, just change the name below and save as application.
In addition, you can add this script as a folder action
Author: Gabriel Zachmann, Feb 2010
*)
property playListName : "Hoerspiele"
on open theseFiles
addTheFiles(theseFiles)
end open
on adding folder items to this_folder after receiving added_items
addTheFiles(added_items)
end adding folder items to
to addTheFiles(theFiles)
tell application id "com.apple.iTunes"

activate

set playL to some playlist whose name is playListName
set playID to persistent ID of playL
--display dialog ("persistent ID = " & playID) buttons {"OK"} default button 1

reveal (some playlist whose persistent ID is playID)

repeat with aFile in theFiles
try
add aFile to some playlist whose persistent ID is playID
end try

-- set new date, so we know later when we copied the files
set the file_path to the quoted form of the POSIX path of aFile
do shell script ("/bin/touch " & file_path)

end repeat

end tell

end addTheFiles


Message was edited by: GabrielZ

MacBook Pro, Mac OS X (10.6.2), iPhone 3GS w/ FW 3.1.2, iTunes 9.0.1

Posted on Mar 16, 2010 4:39 AM

Reply
1 reply

Mar 16, 2010 8:08 AM in response to GabrielZ

folder actions have always been buggy and this has always been an issue when folder actions have to process many files at the same time. it's supposed to have gotten better in snow leopard but it's still very far from being reliable. you can try the following trick to slow down your folder action and make it wait to process individual items before they are all copied. that might (or might not ) help
http://discussions.apple.com/message.jspa?messageID=8277780#8277780

Folder action kicks in too early

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.