I did try this before, but to be honest I found this script on the internet, and not being very clued up with applescript I haven't modified it much. It's written as a folder action, and the only mods Ive made are to make it run in my folder structure, and to use the apple tv2 preset.
If anyone is able to modify it to run as a self contained applescript which i can run within hazel, I'd be grateful.
Here it is;
on adding folder items to this_folder after receiving added_items
with timeout of (720 * 60) seconds
tell application "Finder"
--Get all AVI and MKV files that have no label color yet, meaning it hasn't been processed
set allFiles to every file of entire contents of ("iTunes 2:downloads:Media files" as alias) whose ((name extension is "mkv" or name extension is "avi") and label index is 0)
--Repeat for all files in above folder
repeat with i from 1 to number of items in allFiles
set currentFile to (item i of allFiles)
try
--Set to gray label to indicate processing
set label index of currentFile to 7
--Assemble original and new file paths
set origFilepath to quoted form of POSIX path of (currentFile as alias)
set newFilepath to (characters 1 thru -5 of origFilepath as string) & "m4v'"
--Start the conversion
set shellCommand to "/Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " -e x264 -q 20.0 -r 29.97 --pfr -a 1,1 -E faac,copy:ac3 -B 160,160 -6 dpl2,auto -R Auto,Auto -D 0.0,0.0 -f mp4 -4 -X 1280 --loose-anamorphic -m"
do shell script shellCommand
--Remove the old file
set shellCommand to "rm -f " & origFilepath
do shell script shellCommand
on error errmsg
--Set the label to red to indicate failure
set label index of currentFile to 2
end try
end repeat
end tell
end timeout
end adding folder items to
Thanks