Tuesday, March 24, 2009

AppleScript / Automator: Import AVI video to iTunes as a TV Show or Movie

This is a sweet AppleScript / Automator Workflow that I created which totally automates the task of importing an AVI video into iTunes.
  • Select one or more video files to import. Works on AVI as well as other formats like M4V.
  • Adds metadata to the AVI files to make them iTunes compatible.
  • Prompts if you would like to import into Movies or TV Shows.
  • Sets iTunes metadata to identify the video as Movie or TV Show depending on your choice.
Here is a screenshot of my workflow and here is the workflow file (in a tarball...workflows actually are directories it seems...).


  1. To install as a Finder plugin (so you can select files in Finder then secondary-click / control-click and choose Automator -> Import to iTunes), open the .workflow file in Automator and choose Save As Plug-in, then in Plug-in for select Finder and Save.
  2. To install as an application so you can drag and drop files onto the application, open the .workflow file in Automator and choose File -> Save As and in File Format choose Application.

The AppleScript code is here if you want to copy and paste it:

on run {input, parameters}
 set videoType to button returned of (display dialog ("What type of video are you importing?") buttons {"Movie", "TV Show"} default button {"TV Show"})
 repeat with i in input
   tell application "Finder" to set file type of file i to "MooV"
  end try
  tell application "iTunes"
   set newAddition to (add (i as alias))
   if videoType = "TV Show" then
    tell newAddition to set video kind to TV show
   end if
  end tell
 end repeat
 return input
end run

Monday, March 23, 2009

Recursive chmod on files or directories

This is useful when, for example, you need to set execute permissions on every PHP or Ruby file in all directories below your current directory.

Just replace the '*.php' with the name pattern you want to match. Works on Mac OS X 10.5.6.

find . -type f -name '*.php' -exec chmod 755 {} \;

To see which files will be changed use:

find . -type f -name '*.php' -exec echo {} \;

The {} braces are replaced with each filename as find finds each file that matches your pattern. To find directories use -type d.