I´m working on a script to automate the downloads folder and depending on the the kind and size of the incoming files the script works fine or not.
For example, if there are two photos as the incoming files the script detects them and works fine. But in the are two images and a video file, sometimes the script detects the three incoming files but only processes the images because the video has not already been downloaded.
How could I solve this?
Last I heard, folder actions used a simple loop of checking the file size every few seconds, until it stabilizes, and then continues. It sounds like you will have to do something similar.
What version of the OS are you using?
Add a repeat loop in your folder action handler that captures, compares and updates the size of the downloading files on an individual basis. When the size of a file stops increasing, the file is finished downloading. I’d suggest you check the size every 15 sec. or so till done.
I would have included some code examples but I trashed all my Folder Actions when I went to Hazel. If you can’t figure out how to do it, come on back and repost.
Use Hazel which is basically Folder Actions on steroids plus it’s more reliable and easier to maintain.
I have just updated to 10.11.6
Thanks for your reply. I did´t know anything about Hazel.
Hazel makes Folder Actions livable plus it can do far more. Check out the Forum link at the Hazel site.
Well they’re allegedly more reliable in 10.11. But a loop checking file size is the way to go. It could be that the one Apple is using is simply not waiting long enough between checks; things like where the item is being copied from can make a difference.
Yeah, manual checking for large files is kind of a thing you have to do. This is the check code for a script I used back in the 10.2 days because AV couldn’t autoscan new files. I used a three second delay as connection speeds at the time still involved modems. Not fast, but it seemed to do the trick reliably.
repeat with x in added_items set theFileInfo to info for x --get info for the downloading file(s) set theBaseSize to size of theFileInfo --get initial size delay 3 --wait 3 seconds set theFileInfo to info for x --get info again set theCompareSize to size of theFileInfo --get a newer size repeat while theCompareSize ≠ theBaseSize --if they don't equal, loop until they do set theBaseSize to theCompareSize --new base size delay 3 --wait three seconds set theFileInfo to info for x --get info set theCompareSize to size of theFileInfo --get a newer size end repeat --once the sizes match, the download is done