Handbrake, AppleTV, and batch conversion

I've been trying hard to get back into shape; part of my plan includes running. My exercise room features a treadmill, a wall-mounted TV, and an AppleTV.  The iPod Touch comes with me and, via Rowmote, controls the AppleTV.  I find it much easier to run while catching up on TV.

If I want to watch episodes for shows I have on my Mac, I need to convert them to the AppleTV movie format (MPEG-4) first so that iTunes will happily sync them to the aTV.  Handbrake is a great, open source, free tool to perform that conversion, but its queueing system - for batch conversion of multiple files - is very cumbersome.  Fortunately, the command line interface (CLI) version of Handbrake can do the job with just a touch of magic.

To convert a folder of movie files to the AppleTV format:

1. Download the HandbrakeCLI tool.  I installed it to ~/bin but anywhere on your path will do.

2. Load Terminal and cd to the folder with your movie files.

3. Run the following one-line command:

for f in *; do HandBrakeCLI -i "$f" -o "~/Desktop/$f.mp4" --preset="AppleTV"; done

I've gotten a bit fancier, using screen so I can put the conversion in the background and putting the command into a shell script, but the line above is the key. Hope that helps someone else!