Actually, this is not as crazy as it sounds, I wanted to automate the whole process of file conversion using Handbrake and then adding to iTunes. In the past, I used iSquint for this, but alas, iSquint is no more. The new version of Handbrake supports conversions from files, instead of only from DVD's.
This is how I did it:
- Use HandbrakeCLI to convert the files to MP4 format, using a script along these lines. I found this HandbrakeCLI guide to be very handy. This script is not foolproof - it should check to make sure the file exists before calling HandbrakeCLI, etc., but it shows the concept.
for i in $*
do
echo starting $i at `date`
base=`basename $i .avi`
/Applications/HandBrakeCLI -i $i -o $base.mp4 --preset="iPhone & iPod Touch"
echo ending $i at `date`
done - Use AppleScript to add it to iTunes, as in this script.
for i in $*
do
if [ -f $i ];
then
echo adding file $i
osascript -e "tell application \"iTunes\" to open POSIX file \"$i\""
fi
done
The trick here is that you need to specify the full path when calling this script, something like this:
$ add-to-itunes.bash `pwd`/*.mp4
otherwise the AppleScript will fail:
29:63: execution error: iTunes got an error: Can’t make some data into the expected type. (-1700) - And that's it! iTunes automatically starts playing the file, this is an option that you can turn off via preferences.