Managing Downloaded TV Shows By Folder With Applescript
I’m using the TV Shows Mac application to pull torrent files of TV shows and stream them to my PS3 using the PS3 Media Server application. The flow is something like this:
- TV Shows looks for torrent files and places them in the Media Temp directory.
- Transmission looks torrent files in the Media Temp directory, it deletes the torrent files and puts the in-process and incomplete torrent files in the Media Temp directory.
- When Transmission is done downloading, it moves the file to the TV Shows directory.
What neither TV Shows or Transmission does is to organize shows into separate folders by show name. To achieve this I created a folder action Applescript that parses out the TV show name from the file name and creates a folder. The folder action will then move the file into the appropriate folder.
Here is the folder action that I attach to the TV Show folder. It runs every time a file is placed into the TV Shows folder. (note: This is used on Mac OS X 10.6)
–Organize TV shows by folder
–By Gregory J. Smith http://greginthedesert.net
on adding folder items to this_folder after receiving these_items
tell application “Finder”
try
set tvshowsfolder to this_folder
set thefilelist to these_items
repeat with i from 1 to number of items in thefilelist
set thefilename to name of (item i of thefilelist)
set OldDelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “.”
set Pasrsedfilename to text items of thefilename
set AppleScript’s text item delimiters to OldDelims
–Hopefullug there is never a TV show named SxxExx.
set LastPartOfShowName to (count of Pasrsedfilename) – 1
repeat with x from 2 to number of items in Pasrsedfilename
if (item 1 of (item x of Pasrsedfilename) is “S” and item 4 of (item x of Pasrsedfilename) is “E”) or (item x of Pasrsedfilename) is “REPACK” then
set LastPartOfShowName to x – 1
exit repeat
end if
end repeat
set OldDelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to ” “
set TVShowName to (items 1 through LastPartOfShowName of Pasrsedfilename) as text
set AppleScript’s text item delimiters to OldDelims
log TVShowName
if not (exists folder TVShowName of tvshowsfolder) then
make new folder at tvshowsfolder with properties {name:TVShowName}
end if
move (item i of thefilelist) to ((tvshowsfolder & TVShowName) as string)
end repeat
on error theerror
display dialog “There was an error moving TV shows: ” & theerror
end try
end tell
end adding folder items to
The applescript seems to work pretty well when there is only one show that lands in the TV Shows directory. When I have manually added several files to the TV show directory, sometimes the folder actions just stop working or give a weird error.
My next project will be to automatically delete the TV shows based the last time they were viewed. The challenge here will be that the PS3 Media Server doesn’t do anything to mark a file as read and I don’t want to delete a file unless it has been watched.



Traveling with Southwest Airlines is now even more convenient with our first iPhone app. Make reservations, check in for flights, and access your Rapid Rewards account directly from your iPhone. Plus, our iPhone app has DING! functionality built in, giving you instant access to exclusive, limited-time-only air fare deals. When a DING! fare is made available, you’ll be notified immediately on your iPhone.


Recent Comments