All posts tagged Automator

Batch convert animated GIFs to videos using AppleScript/Automator/QuickTime 7 on OS X

When I was doing a VJ thing, the software I used couldn’t handle the animated GIF files I wanted to play. I had a hard time finding a free tool to batch convert animated GIF to movie and not the other way round.

Since I just made that video AppleScript/QuickTime batch converter I thought I could do the same thing with GIFs too. It turned out the standard QuickTime X can’t open them. But QuickTime 7 can! And you can still install it from your OS X Install Disk – at least with Snow Leopard.

So just install QuickTime Player 7 and put this Automator .workflow file into your ~/Library/Services folder. Now select one or more animated GIF files in Finder, right-click them, and choose Services → Convert animated .gif to .mov using QuickTime 7. It will use the most recent QuickTime 7 export settings. You should convert/export one file by hand to adjust the settings.

You’ll see QuickTime Player 7 starting and magically converting one file after another. I found it’s better to leave it alone while it’s doing that.

 

How to do this from scratch?

See my AppleScript/QuickTime batch converter post on how to create a Service for Finder Contextual Menu (the thing that pops up when you do a right-click). But in step 2 use image files instead of movie files and in step 4 use this code:

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

	display dialog "Most recent QuickTime 7 export settings will be used.
Existing files will be overwritten/moved to trash!
Beware of evil QT7 Gamma shift!"

	tell application "QuickTime Player 7"
		activate
		close every window
	end tell

	repeat with currentItem in droppedItems
		tell application "Finder" to set fileName to name of currentItem as Unicode text

		tell application "QuickTime Player 7"
			open currentItem
			tell front document to set frameCount to count of frames of first track
		end tell

		set outputFileName to (outputFolder & fileName & ".mov")

		tell application "Finder"
			if exists file outputFileName then
				delete file outputFileName
			end if
		end tell

		tell application "QuickTime Player 7"
			if frameCount is greater than 1 then
				with timeout of 86400 seconds -- 24 hours
					export front document to outputFileName as QuickTime movie using most recent settings
				end timeout
			end if
			close front document
		end tell
	end repeat

	quit application "QuickTime Player 7"
end open

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?
Yes!
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 original-filename.original-extension.mov.

 

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
		return
	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.