IsBusy Handler problem...

I am pretty sure I messed up the IsBusy script and handler by not undestanding the instructions provided in them…

I get an error message that the variable testResults is not defined…

Could someone please let me know how I managed to mess it up??


Here they are:

global CurrentFileSize, LastFileSize, StillBusy, StillGrowing
on adding folder items to this_folder after receiving added_items
		-- 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)
	on error errmsg
		display dialog errmsg
	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
		--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 "Macintosh HD:Library:Scripts:Folder Action Scripts:IsBusy().scpt" with parameters {File2Check, LastFileSize}
			set CurrentFileSize to item 2 of testResults
			if item 1 of testResults is true then
				set Ready2Rock to true
				set LastFileSize to CurrentFileSize
			end if
			delay 1
		end repeat
		-- now that the file has finished writing, 
		-- process the file while it's in this folder 
		-- because the file is so big 
			tell application "Finder" to duplicate alias (item x of added_items) to folder "Macintosh HD:Users:ishelp:Desktop:Upload Folder"
		on error errmsg
			display dialog errmsg
		end try
		-- 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 (file_to_check) to folder "path:to:done:folder:" -- intertpret as necessary 
	end repeat
end ProcessAddedItems

And then there is the handler, which I saved in my folder action scripts folder:

f: file path, alias, posix path
isBusy("path:to:file.txt") --> false

to isBusy(f)
	set f to f as Unicode text
	if f does not contain ":" then set f to POSIX file f as Unicode text
	if busy status of (info for alias f) then return true
	--> but some times this is not good enough
		open for access file f with write permission
		close access result
		return false
	on error
		return true
	end try
end isBusy

Try downloading isDone() from Code Exchange. The code you are using requires it. Look carefully at the comments at the top of the isDone() handler for implementation info.


Oops :oops: … all along I thought the script needed IsBusy …
I guess I’ve been so busy trying to modify tiny things in my script that the simplest
answers pass me by…

Thanks…I’ll try it again next time I’m around my Mac!