PDA

View Full Version : TV Show file Sorting Apple Script




BrianDowner
Feb 15, 2009, 01:52 PM
The purpose of this Script is to sort TV shows into Folders of the same name. I have to use the first word of the file name to identify the TV show. That part works great. The script is unable to identify the destination folder with the same name. I've racked my brain and googled the world to solve this but have come up with nothing. If any one can help I would very much appreciate it.

The problem I'm having is on this line:



move selection to folder whose name begins with theCurrentValue of disk "tv"


See what happens:


get some file of disk "tv" whose name starts with "Psych"
document file "Psych.S03E13.HDTV.XviD-aAF.avi" of disk "tv"
exists document file "Psych.S03E13.HDTV.XviD-aAF.avi" of disk "tv"
true
select every file of disk "tv" whose name starts with "Psych"
{document file "Psych.S03E13.HDTV.XviD-aAF.avi" of disk "tv", document file "Psych.S03E14.HDTV.XviD-aAF.avi" of disk "tv", document file "Psych.S03E15.HDTV.XviD-aAF.avi" of disk "tv"}
"Canít get folder whose name starts with theCurrentValue of disk \"tv\"."




Full Script:


set tvShowFirstWordOfFileName to {"Heroes", "Psych", "Battlestar", "Lost", "Ghost", "Monk", "The", "How", "Smallville"}


tell application "Finder"

repeat with theCurrentValue in tvShowFirstWordOfFileName

set testFile to {}

try
set testFile to (some file of disk "tv" whose name begins with theCurrentValue)
end try

if exists testFile then
select (every file of disk "tv" whose name begins with theCurrentValue)
move selection to folder whose name begins with theCurrentValue of disk "tv"
end if

end repeat

end tell