Compressor via Shell with Automaic Folder organization

I’ve written a somewhat complex script that works, but not well. I’m looking for some input/suggestions to help improve it.

What it does:
The files are titles similar to “ABC002_HD” or “ABC123_HD Subclip” or “ABC321_HD Subclip 3”
There are about a hundred sent to compressiong a day, and each is about 5 minute long uncompressed .mov HD footage. Some are 30 minutes.

  1. The script runs at 8:00pm every day.
  2. Takes every file in the folder “TO_COMPRESS”. For every file in the folder it adds to an array. It goes through every file and:
    2a. Checks to see if a folder exists in “COMPRESSED” titled like the file (if the file is called “ABC002_HD” the folder will be “ABC002”, if the file is “ABC123_HD Subclip 2” the folder is “ABC123”)
    if not create the folder and two folder inside it “WMV” and “FLV”
    2b. Move the file from “TO_COMPRESS” to “COMPRESSING”
    2c. run a shell script for compressor to compress the file in a bunch of different formats and settings. If the file to compress is a .wmv, it goes in the “WMV” folder, same for .flv’s
  3. Go to next file in the array

The problem I’m having seems to be the script takes to many system resources. It either times out, or skips over files. The folder naming and file moving seem to work great.
I believe it has something to do with using aliases.

I’m using one machine as strictly a cluster controller. It’s a fairly new xserve quad with 10.5.1. The rest of the machines are Intel quad Xserves with 10.5 and all of the machines have proper plugins needed. (they work fine with droplets and Compressor normally). The clusters all work fine normally.

The Script (Feel free to use, works great with small files)

(**** fast search and replace methods ****)
on snr(the_string, search_string, replace_string)
	return my list_to_string((my string_to_list(the_string, search_string)), replace_string)
end snr

on list_to_string(the_list, the_delim)
	my atid(the_delim)
	set the_string to (every text item of the_list) as string
	my atid("")
	return the_string
end list_to_string

on string_to_list(the_string, the_delim)
	my atid(the_delim)
	set the_list to (every text item of the_string) as list
	my atid("")
	return the_list
end string_to_list

on atid(the_delim)
	set AppleScript's text item delimiters to the_delim
end atid

tell application "Finder"
	set clusterid to "Kraven"
	set Afolder to "kravenscratch:TO_COMPRESS" as alias
	set Bfolder to "kravenscratch:COMPRESSING" as alias
	set Cfolder to "kravenscratch:COMPRESSED" as alias
	set a_list to every file in Afolder as alias list
end tell

repeat with i from 1 to number of items in a_list
	tell application "Finder"
		set a_file to (item i of a_list)
		move a_file to Bfolder
		set mediafile to POSIX path of a_file
	end tell
	tell application "Finder"
		set filename to mediafile
	end tell
	set step1 to snr(filename, "/Volumes/kravenscratch/COMPRESSING/", "")
	set step2 to snr(step1, "", "")
	set step3 to snr(step2, ".mov", "")
	set dest to snr(step3, " ", "_")
	(*make new folder for each episode by deleting every possible extension up to 9 sublcips*)
	set folderstart to snr(filename, " ", "_")
	set foldername6 to snr(folderstart, "_1", "")
	set foldername7 to snr(foldername6, "_2", "")
	set foldername8 to snr(foldername7, "_3", "")
	set foldername9 to snr(foldername8, "_4", "")
	set foldername10 to snr(foldername9, "_5", "")
	set foldername11 to snr(foldername10, "_6", "")
	set foldername12 to snr(foldername11, "_7", "")
	set foldername13 to snr(foldername12, "_8", "")
	set foldername14 to snr(foldername13, "_9", "")
	set foldername1 to snr(foldername14, "/Volumes/kravenscratch/COMPRESSING/", "")
	set foldername2 to snr(foldername1, ".mov", "")
	set foldername3 to snr(foldername2, "_Subclip", "")
	set foldername4 to snr(foldername3, "_HD", "")
	set foldername5 to snr(foldername4, "_", "")
	set foldernamefinal to foldername5
	tell application "Finder"
		set pathto to "kravenscratch:COMPRESSED:" & foldernamefinal
		if exists folder pathto then
			make new folder at alias "kravenscratch:COMPRESSED:" with properties {name:foldernamefinal}
			make new folder at alias ("kravenscratch:COMPRESSED:" & foldernamefinal) with properties {name:"WMV"}
			make new folder at alias ("kravenscratch:COMPRESSED:" & foldernamefinal) with properties {name:"FLV"}
		end if
		set destto_WMV to POSIX path of pathto & "/WMV/"
		set destto_FLV to POSIX path of pathto & "/FLV/"
	end tell
	do shell script "/Applications/ -clustername '" & clusterid & "' -batchname '" & dest & "' -priority low -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/WMV_PIF_v1/WMV_PIF_1.setting' -destinationpath ' " & destto_WMV & dest & "_150.wmv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/WMV_PIF_v1/WMV_PIF_2.setting' -destinationpath '" & destto_WMV & dest & "_450.wmv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/WMV_PIF_v1/WMV_PIF_3.setting' -destinationpath '" & destto_WMV & dest & "_750.wmv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/WMV_PIF_v1/WMV_PIF_4.setting' -destinationpath '" & destto_WMV & dest & "_1000.wmv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/WMV_PIF_v1/WMV_PIF_5.setting' -destinationpath '" & destto_WMV & dest & "_2000.wmv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/FLV_v1/FLV_1.setting' -destinationpath '" & destto_FLV & dest & "_150.flv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/FLV_v1/FLV_2.setting' -destinationpath ' " & destto_FLV & dest & "_450.flv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/FLV_v1/FLV_3.setting' -destinationpath '" & destto_FLV & dest & "_750.flv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/FLV_v1/FLV_4.setting' -destinationpath '" & destto_FLV & dest & "_1000.flv' -jobpath '" & mediafile & "' -settingpath '/Users/kraven/Library/Application Support/Compressor/FLV_v1/FLV_5.setting' -destinationpath '" & destto_FLV & dest & "_2000.flv'"
	delay 60
end repeat