This is a folder action handler that waits for file(s) to finish writing to the folder you attach it to. It calls my isDone() handler.
OS version: OS X
-- written by Jeff Case 2004
property LSreturn : ""
global CurrentFileSize, LastFileSize, StillBusy, StillGrowing
on adding folder items to this_folder after receiving added_items
try
-- get the name of the folder
tell application "Finder"
set the folder_name to the name of this_folder
-- find out how many new items have been placed in the folder
set the item_count to the number of items in the added_items
end tell
ProcessAddedItems(this_folder, added_items, item_count)
end try
end adding folder items to
on ProcessAddedItems(this_folder, added_items, item_count)
-- loop through the files looking for finished files to process
repeat with x from item_count to 1 by -1
set File2Check to (item x of added_items) as string
set AppleScript's text item delimiters to ":"
set TheFileName to text item -1 of File2Check
set AppleScript's text item delimiters to ""
set LastFileSize to -1
set Ready2Rock to false
beep
--loop waiting for the file to finish writing
repeat until Ready2Rock is true
-- modify the path accordingly - point to isDone().scpt on your machine
set testResults to run script alias "OSX:Users:ByteJockey:Library:Scripts:JScripts:isDone().scpt" with parameters {File2Check, LastFileSize}
set CurrentFileSize to item 2 of testResults
if item 1 of testResults is true then
set Ready2Rock to true
else
set LastFileSize to CurrentFileSize
end if
(*
-- Wanna monitor the progress??
-- un-comment this block of code
set AppleScript's text item delimiters to return
tell me
activate
display dialog (TheFileName & return & testResults) as string buttons {"OK", "Cancel"} ¬
default button 1 giving up after 1
end tell
set AppleScript's text item delimiters to ""
*)
delay 1
end repeat
-- now that the file has finished writing,
-- process the file while it's in this folder
-- if the file is so big another move would
-- require another isDone() check
tell me
activate
display dialog ("The file: " & return & return & TheFileName & return & CurrentFileSize & return & return & " is ready to process.") ¬
buttons {"OK", "Cancel"} default button 1 giving up after 2 without static
end tell
-- (YOU MAY OR MAY NOT WANT TO DO THE FOLLOWING, DEPENDING ON YOUR NEEDS)
-- then move the file to a "done" folder
-- so the folder action can pick up
-- a new file with the same name
-- because Folder Actions don't "see" overwrites
-- only new files added are acted upon, not updates or overwrites
-- tell application "Finder" to move alias (File2Check) to folder "path:to:done:folder:" -- intertpret as necessary
end repeat
end ProcessAddedItems