Hallo,
I have a folder action script which watches the folder and does three things:
a) copy the file to another folder on a network (a raid folder)
b) start a shell-cmd which renames the file on the network volume
In the folder fall files from compressor.
The folder script checks when the files are completely processed (no size change any more)
and then starts.
It usually works (about 90% of the time), but sometimes it takes a long time until a file
is sent to the network volume.
This morning:
compressor sent 5 files to the folder (they arrived completely in the action script folder in the order):
12345
The script copied the 5 files like this.
23451
This means File 4 and 5 where in the network volume 1 Minute after the arrived fully in the folder action folder.
It took 30 minutes between file 1 arriving in the folder action folder completely (no size change any more) and being copied to the network volume.
Question:
Has anyone seen something similiar happening?
Sometimes files do not being sent by the appleccript at all (or we are not waiting long enough)
Can anyone guess what the reason is and whether and what remedy is for it?
This is relevant part of the script (I think):
on adding folder items to this_folder after receiving added_items
set the item_count to the number of items in the added_items
if the item_count is greater than 0 then
with timeout of 3600 seconds
repeat with theFile in added_items
set Was to 0
set isNow to 1
repeat while isNow ≠Was
set Was to size of (info for theFile)
delay 5 -- longer if getting the item is slow
set isNow to size of (info for theFile)
end repeat
schneide(theFile)
end repeat
end timeout
end if
Folder action scripts are not reliable. There are lots of posts about it just do a Google search if you want
to learn more.
The most reliable way to watch a folder is by using launchd. Search the forum since there is already a
considerable amount of information about launchd.
Hi,
I started to test launchd, but the big problem is, that launchd:
a) In my oppinion starts when the file starts to arrive, not after it is completely copied into the folder:
I deal with video processing, so it can take some time until a video file is saved completely by compressor.
b) launched calls my apple script, but the script does not know, which file changed because I have found no diect
way to give the new/changed File to the apple script.
So I either need to have a shell script in between to find out which file is new or let say java do the whole thing (checking for new file, checking for file completely saved and then processing it, but that seems to be overkill.
Any hint how I can find out easily which file to process?
One example is to use a text file. Get all the files in the folder and write them to a file
the first time the script runs and then in subsequent runs check the file
names in the folder against the file names in the text file. Once the file
is processed remove its name from the text file.
Another way would be to change the label color of the files once they are
added to the folder. Your script would check for all files not having that
color and then start processing them which would include changing their
color.
You could also use a stay open script that watches the folder and keeps
up with which files need to be processed.
Nothing wrong with using Java to handle this either if you already know it.