Announcement
I've posted a new tutorial thread in the Apple TV and Home Theater forum:
How-To: Automating DVD & Blu-Ray (Backup, Encoding & Tagging) for Mac OS X 10.6
I hoping this one will die a graceful death.![]()
Enjoy!
Part 5: Automating DVD Backup with FairMount, HandBrake and iTunes
Parts to this tutorial:
Part 1: Introduction
Part 2: Using AppleScript to Automate Ripping
Part 3: Using a Batch Script to Automate HandBrake
Part 4: TV Show Renamer Droplet
Part 5: Add to iTunes and Auto-tag Script
Add to iTunes and Auto-tag Script
This AppleScript parses the video files' filenames, creates a playlist named AutoAdd on a remote machine, adds the file to the new iTunes playlist, tells iTunes to set the Episode or Movie name, season#, episode#, episodeID, Video Kind and Show Name. It then deletes the playlist leaving the files in their respective TV or Movie playlists.
This was created to be a folder action attached to a TV Shows and/or Movies Folder. The script is executed whenever new files are added to these folders.
Optional: If you keep your files on one machine and your iTunes Library is located on a remote machine (like a Mac Mini), you could edit this script to add the files the remote machine's iTunes Library. See the optional steps listed below.
Creating Your Script:
- Select, copy and paste the script below into a new Script Editor document.
Code:-- ADD TO ITUNES AND AUTO-TAG SCRIPT (* This AppleScript parses the video files' filenames, creates a playlist named AutoAdd on a remote machine, adds the file to the new iTunes playlist, tells iTunes to set the Episode or Movie name, season#, episode#, episodeID, Video Kind and Show Name. It then deletes the playlist leaving the files in their respective TV or Movie playlists. This was created to be a folder action attached to a TV Shows and/or Movies Folder. The script is executed whenever new files are added to these folders. OPTIONAL: If you are adding to remote computer's iTunes Library, you will need to make a couple edits to this script: 1. Add the remMachine variable below. 2. On the line: Tell application "iTunes", delete the "--" before "of machine remMachine" so it reads: tell application "iTunes" of machine remMachine. 3. Enable "Remote Apple Events" in the Sharing Preference Pane on the remote machine. For more info visit http://dougscripts.com/ *) on adding folder items to my_folder after receiving the_files global allRemPlaylists, remMachine -- OPTIONAL: If you are adding to remote computer's iTunes Library -- Change the remMachine to your remote machine's info: set remMachine to "eppc://username:userpass@remote_ip.local" (* where username is something like "doug", userpass is the password, remote_ip is the IP address see in the remote machine's Sharing Pane, something like "192.168.2.1" or "your-remote-machine.local" Note: On some configurations an administrator username and password are needed. *) using terms from application "iTunes" try -- OPTIONAL: If you are adding to remote computer's iTunes Library- -- Edit the line below and delete the "--" before "of machine remMachine". It should read: tell application "iTunes" of machine remMachine tell application "iTunes" --of machine remMachine launch make new user playlist with properties {name:"AutoAdd"} repeat with i from 1 to number of items in the_files set this_file to (item i of the_files) add this_file to playlist "AutoAdd" end repeat (* -- if you have iTunes set to --"Copy files to iTunes Music folder when adding to library" -- then you might want to delete the original file... -- if so, remove comments from this block and -- use the UNIX commands below to delete the file set the file_path to the quoted form of the POSIX path of this_file do shell script ("rm -f " & file_path) *) set userPlaylist to user playlist "AutoAdd" set movieTracks to (tracks of userPlaylist) repeat with movieTrack in movieTracks set movieTrackName to name of movieTrack as string set AppleScript's text item delimiters to "_" set tokens to (every text item of movieTrackName) as list if the (count of items in tokens) > 1 then set video kind of movieTrack to TV show set season number of movieTrack to item 1 of tokens set episode number of movieTrack to item 2 of tokens set name of movieTrack to item 4 of tokens set disc number of movieTrack to item 1 of tokens set show of movieTrack to item 3 of tokens set episode ID of movieTrack to ((item 1 of tokens as integer) * 100 + (item 2 of tokens)) as integer end if set comment of movieTrack to "original track name: " & movieTrackName end repeat delete user playlist "AutoAdd" end tell end try end using terms from end adding folder items to
- Choose Script > Compile (CMD-K)
Optional: If you are adding to are remote machine:
- Change the "remMachine" variable: Insert the remote machines's username, password and IP address (eppc://username:userpass@remote_ip.local)
- On the line: Tell application "iTunes", delete the "--" before "of machine remMachine" so it reads: tell application "iTunes" of machine remMachine.
- Enable Remote Apple Events on the remote machine:
- Open System Preferences and click Sharing.
- Turn on Remote Apple Events by checking the checkbox.
- Close the window to save your settings.
- Save the edited script as "Add to iTunes Auto-Tag.scpt".
- Move the script file to your Mac's main Folder Action Scripts folder (Macintosh HD/Library/Scripts/Folder Action Scripts/). Note: The script may not execute if located elsewhere on your system.
Enabling Folder Actions
- Right-Click (Control+Click) on the folder you want to attach the folder action to (ex. ~/Movies).
- Scroll to the bottom of the pop-up and Select More > Enable Folder Actions
- Right-Click (Control+Click) on the folder again and Select More > Attach a Folder Action
- Navigate and Choose your "Add to iTunes Auto-Tag.scpt"
- The script should now execute whenever files are added to this folder.
Note: If you keep your movie files and TV files in separate folders, you may want to repeat these steps on your other media folders.