Batch convert AVI and other videos files via the Contextual Menu in Finder using AppleScript/Automator/QuickTime on OS X

I really like my Canon IXUS camera, but when it comes to making videos it always bugged me having these huge uncompressed .avi files filling up my disk. QuickTime is free and has a .H264 export option with some presets built in, but no batch mode. You have to convert videos by hand – one at a time.

If I had lots of files, wouldn’t it be much easier to just select some video files in Finder, right-click and convert them?
And it is all possible using AppleScript, Automator and the Contextual Menu – a.k.a. Services.

Just put this Automator .workflow file into your ~/Library/Services folder. Now select one or more movies in Finder, right-click them, and choose Services → Convert video(s) using QuickTime. You can choose between the presets QuickTime offers… try them and see what they do. I usually use 480p and 720p.

You’ll see QuickTime Player starting and magically converting one video file after another. I found it’s better to leave it alone while it’s doing that. Your files will be output as


How to do this from scratch?

1. Open up Automator, which comes with OS X. Create a new Service with FileNew… and choose the Service template.


2. At the top of the window, set up the Service to receive movie files from Finder.


3. From the left side, drag a Run AppleScript action into your workflow in the middle.


4. Insert this AppleScript into your action:

on run {inputFiles}
	if inputFiles is equal to {} then
		set inputFiles to (choose file with prompt "Select the file(s) to convert:" with multiple selections allowed without invisibles)
	end if
	open inputFiles
end run

on open droppedItems
	tell application "Finder" to set inputFolder to (container of first item of droppedItems) as Unicode text
	set outputFolder to (choose folder with prompt "Select output folder:" default location (inputFolder as alias)) as Unicode text

	set exportPreset to (choose from list {"Movie", "iPhone", "iPod", "HD 480p", "HD 720p"} with prompt "Choose QuickTime Export Preset:") as Unicode text
	if exportPreset is equal to "false" then
	end if

	repeat with currentItem in droppedItems
		repeat until getProcessPercentCPU("CoreMediaAuthoringSessionHelper") is equal to ""
			delay 30
		end repeat

		tell application "Finder" to set fileName to name of currentItem as Unicode text
		convertFile(currentItem, outputFolder & fileName & ".mov", exportPreset)
		delay 30
	end repeat
end open

on convertFile(inputFile, outputFile, exportPreset)
	tell application "QuickTime Player"
		set thisMovie to open inputFile
		export thisMovie in (outputFile) using settings preset exportPreset
		close thisMovie
	end tell
end convertFile

on getProcessPercentCPU(processName)
	do shell script "/bin/ps -xco %cpu,command | /usr/bin/awk '/" & processName & "$/ {print $1}'"
end getProcessPercentCPU

Then save – I used Convert video(s) using QuickTime as file name. Automator then automatically saves your workflow to your user service directory at ~/Library/Services. If you don’t want it any more, just delete it.