Folder action kicks in too early
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