Subroutine problem

Hi

I have a subroutine which will not run and I am guessing that it is because the variables passed to it are causing problems. Basically, the routine below checks a folder to see if files are over a certain size then splits them if so. But I keep getting an Applescript runtime error: “Finder got an error: Can’t continue splitFile.”

Can someone tell me what I am doing wrong? The subroutine works fine if I manually select a file but not when I try and pass a file name to it in the automated way this script does.

Cheers

set MBMax to 5
set mainFolder to (path to current user folder as string) & "Movies:EyeTV Encoded:"
tell application "Finder"
	set fileList to files of folder mainFolder
	set fileCount to count fileList
	repeat with i from 1 to fileCount
		set fileInfo to info for item i of fileList as alias
		set filesize to size of fileInfo
		if filesize > (MBMax * 1000000) then
			set fileToSplit to item i of fileList as alias
			--display dialog (filesize as string) & " " & filepointer as string
			splitFile(fileToSplit, MBMax)
		end if
	end repeat
end tell


to splitFile(fileToSplit, MBMax)
	--> 1 = Hacha; 2 = HJSplit; 3 = FastSplit; 4 = WinSplit; 5 = MacHacha; 6 = Polymorphic
	--> HJSplit is best as produces fewest files and can be reassembled with Split & Concat
	display dialog fileToSplit
	set fileToSplit to fileToSplt as alias
	set MBchunkSize to 5
	set splitFormat to 2
	tell application "Finder" to open fileToSplit ¬
		using application file id "com.pescadosweb.machacha"
	
	tell application "MacHacha"
		repeat
			if visible of window "split" then exit repeat
			delay 0.2
		end repeat
		
		tell window "split"
			set contents of text field "size" to MBchunkSize
			set selected row of table view 1 of scroll view 1 to splitFormat
			ignoring application responses
				tell button "oksplit" to perform action
			end ignoring
		end tell
		
		--> just in case you wanna surpase res-fork dialog:
		delay 0.5
		if name of window 1 is not "progress" then --> we have a warning dialog
			tell application "System Events" to ¬
				tell process "MacHacha" to ¬
					perform action "AXPress" of last button of window 1
		end if
		
		--> now, monitorize if you wish:
		repeat
			if not visible of window "progress" then exit repeat
			delay 0.5
		end repeat
		tell application "Finder" to move fileToSplit to trash
	end tell
end splitFile

Hi kiwi,

subroutine calls within a tell block work only with the prefix my

my splitFile(fileToSplit, MBMax)

does it

Stefan is right on the mark here - otherwise, the Finder tries to interpret “splitFile” in its own dictionary, doesn’t find it, and gives up. “my” or “of me” refers to the script itself, telling the script that this is not a Finder instruction - it’s elsewhere in the script itself.

Thanks very much. Made the change and it all worked without a hitch.

:slight_smile: