I am trying to create a folder script that will move downloaded files to a server. It takes Finder up to an hour to complete the job depending on the file size. It’s a USB disc attached to an Airport so there are plenty GB copied over Wi-Fi.
I have a script that works for smaller downloads. But with bigger files I suppose the script times out. I tried incorporating some delay scripts but I can’t make it work. Maybe someone here knows how to do it?
on adding folder items to thisFolder after receiving added_items
set new_download to (POSIX file "/Volumes/Files/INCOMING") as string
repeat with addedFile in added_items
try
tell application "Finder"
move addedFile to alias new_download with replacing
end tell
--> after the Finder copy is done I would like too secure delete addedFile
tell application "Finder"
delete addedFile
empty trash with security
end tell
on error
display dialog "Problems moving " & (name of addedFile) with icon caution with title "Oops..."
end try
end repeat
end adding folder items to
The problem is that I don’t know the time. Sometimes it takes 10 min and sometimes it takes 50 min. I need something that waits for Finder to finish. I could of course set the time to 75 min and cover most cases but that would be a rather ugly solution.
I know there is an “on folderReady()” subroutine that I have found and used in the past, by searching this forum.
It basically keeps checking a files filesize and waits until it stops increasing.
I know this is for a folder action that checks files added to the folder with the folder action attached, but maybe you could do something similar for the receiving folder??
on adding folder items to this_folder after receiving these_items
if folderReady(this_folder) then
repeat with an_item in these_items
-- insert your script here
end repeat
end if
end adding folder items to
on folderReady(tFolder)
set myFolder to tFolder as alias -- use the path to the folder that's loading
set firstSize to size of (info for myFolder) --get initial size
delay 3 --wait 3 seconds
set newSize to size of (info for myFolder) --get a newer size, bigger
repeat while newSize ≠firstSize --if they don't equal, loop until they do
set firstSize to newSize --new base size
delay 3 --wait three seconds
set newSize to size of (info for myFolder) --get a newer size
end repeat --once the sizes match, the transfer is complete
return true
end folderReady
I wonder if the folder action has started running before the file is downloaded or if the problem is with
on adding folder items to thisFolder after receiving added_items
itself.
Try something like this:
on adding folder items to thisFolder after receiving added_items
repeat with addedFile in added_items
tell application "System Events"
repeat until busy status of addedFile is false
delay 1
end repeat
end tell
-- Insert your code
end repeat
end adding folder items to