Fun with Automator

Automator iconThis post also titled “how to automatically download TV shows and convert them for your iPhone.”


  • I have a shiny new iPhone in need of content
  • TVRSS is great
  • NetNewsWire is godly
  • Transmission makes a fine BitTorrent client
  • VisualHub is an awesome app
  • AtomicParsley is kind to metadata
  • iTunes is not nice with metadata
  • Automator kinda sucks, but can be made functional
  • AppleScript is great
  • Folder Rules FTW

I needed a way to get stuff  from TVRSS into iTunes and onto my iPhone. After most of a weekend hacking and scraping and debugging, and Lather Rinse Repeat, I have come up with an Automator workflow to (in conjunction with everything listed above) automagically find, download via torrent, transcode, metadata-ify, and copy videos to your iProduct of choice. Note, this was tested with an iPhone on an Intel Mac. I will probably not be re-writing this guide for PC users. Your mileage may vary. This is based pretty heavily on LRR’s guide, with a lot of my own modifications.

You will need the following:

Ok, so you’ve got everything installed. Good. Now first make sure you downloaded and installed that script pack for automation from TechSpansion. Download and decompress, then find VisualHub. Right-click, show package contents to see what’s inside the bundle. Copy the script to the Contents/Resources/Scripts folder. Open VisualHub and the title bar should now read “VisualHub 1.x Automation Tech Preview.” If it doesn’t, you screwed up, so start over.

Easy, huh? Just you wait…

In order to use the new automation features of VH correctly now, we must create a file that contains the settings we’re going to use when run automated. When we get to running and building the script, we will load in this settings file and tell VH to go crazy. Fire up VH. Set it to iTunes, optimize for your iProduct of choice (in this example I’m using iPhone, but I’m guessing it’d work fine for the AppleTV or video iPods), and check the H.264 encoding box. Leave the Quality slider at High and make sure the Send to iTunes box is unchecked. Set your Save To path, and make sure you remember it. This will be important later on. Once you have everything set like you’re going to want it, hit the Advanced button and then the Save Settings button. Pick a path (I chose ~/Documents) and name it iphone.vhub.

Now that VisualHub’s setup, let’s go find some shows we want. Go over to and find a show you want. Switch  groups to either EZTV or VTV to avoid duplicates, and then right click and copy the search-based RSS feed. From there, create a new subscription in NetNewsWire with Cmd-N and paste in the feed URL (NNW should auto-paste it.) Once you’ve got the feed subscribed, go into your NNW prefs and into the Downloading section. Set your downloads folder to your Desktop, and create a sub-folder for each feed. Once this is setup, select the feed in your list and hit Cmd-I. Expand the Enclosures section, check the box for Use Custom Setting, and check the box for Other enclosures. Close this and you’re good.

NNW feed settings

Since the .torrent files are enclosed in the feed, NNW will automatically download them and put them in ~/Desktop/NetNewsWire Enclosures/tvRSS – search based. Now we need to tell Transmission to keep an eye on this folder, and automatically add any .torrents that are created.

Fire up Transmission and rip open your prefs. Create a new folder on your desktop, I named it “torrents.” Set NNW to Download to this folder. Check the box for Keep Incomplete File In: and choose the tvRSS – search based folder (~/Desktop/NetNewsWire Enclosures/tvRSS – search based). Check the box to trash original .torrent files. Now the important part: set the tvRSS – search based as the folder to watch for auto-add.


From here, your Transmission configuration is complete. NNW will refresh the search feed every so often, auto-save the attached torrents to a folder that Transmission will keep an eye on. When it sees new torrents, it’ll start downloading them, and once they’re complete it will move the files to ~/Desktop/torrents. This is the important part, because now we’re going to bust out Automator and create a workflow then folder action that will run whenever files are put in the torrents folder.

First, create another folder on your desktop named iphonemovies. Create a subfolder in there called temp. VisualHub is going to get the original files from the torrents folder, transcode them, and dump them in ~/Desktop/iphonemovies/temp.

In Automator, create a new workflow. Add the “Get Specified Finder Items” action in position 1. Leave it blank, since it’ll fill in when we attach it to a folder.

Add a Run AppleScript in position 2. Jam this code in there, replacing with the name of your hard drive and your short username:

on run {input, parameters}
--we need to unset the default timeout length of two minutes, we'll make it 45
with timeout of (45 * 60) seconds

tell application "VisualHub" to set VisualHub to load script (scripts path of main bundle & "/automation.scpt" as POSIX file)

tell VisualHub
end tell
end timeout
return input
delay 15
end run

This will do all the VisualHub fun. From here, we’re doing good, except for one thing. We need to add some metadata so iTunes knows what to sync. In this case, we’re setting the STIK atom to 10, which iTunes recogizes as a TV show. If we don’t set this atom, iTunes will add in this file as a movie, and that caused issues for me. While we’re at it, we’ll set the TV show name to DailyShow, for easier iPhone syncing later.

Add a third action, Run Shell Script in position 3. Set it to ignore results from previous action, and paste this in:

for i in ~/Desktop/iphonemovies/temp/*.mp4; do /Applications/ $i --stik value=10 --TVShowName DailyShow -o $i >> /dev/null;rm $i;done

Add a fourth action, Find Finder Items. Set the Where to ~/Desktop/iphonemovies/temp and the Kind Is Movie.

Add a fifth action, Move Finder Items. Set the To to ~/Desktop/iphonemovies. Make sure this is using the input from the previous action.

Finally, add a sixth action, Run AppleScript.

on run {input, parameters}
tell application "VisualHub" to quit
tell application "iTunes" to add input
end run

Save this workflow somewhere in case you have to edit it later. We’re almost done. With the workflow open, File -> Save As Plug-In. Save it for Folder Actions, name it something like “VH to iPhone,” and attach it to the download folder on your desktop.

Try it out. Drop an avi file into your torrents folder on your desktop. VisualHub should automatically spring in to action, load up the settings for the iPhone, and start transcoding to H.264. Once it’s done, the shell script’ll add the TVShow STIK atom, set the name to DailyShow.

From here, all you have to is set iTunes to sync X most recent episodes of DailyShow and you’re set.


You’re done. There are a couple bugs I’ve found though:

  • If VH is transcoding one file and another one falls into the torrents folder, the folder action won’t run because VH is already open.
  • If you subscribe to multiple shows, make sure the name of the feeds in is NNW the same. Transmission can only watch one folder at a time.
  • Not a bug, but this could be easily expanded to transcode to AppleTV or iPod/Touch, just change the settings in the .vhub file.

Enjoy, and leave comments with issues/etc.