/ Published in: AppleScript
Expand |
Embed | Plain Text
tell application "iTunes" set numberUpdated to 0 if selection is {} then return set sel to a reference to selection repeat with aFile in sel repeat 1 times set mediaType to get video kind of aFile if mediaType is not "none" then #work out the new path and filename set fileLocation to get location of aFile tell application "Finder" set theFile to fileLocation set fileExtension to get name extension of theFile end tell if mediaType is TV show then set newLocation to "BigBird:Movies:#TV" set seasonNumber to get season number of aFile if seasonNumber is less than 10 then set seasonNumber to ("0" & seasonNumber) set showName to get show of aFile as string set showName to my findAndReplace(":", "", showName) set episodeNumber to get episode number of aFile if episodeNumber is less than 10 then set episodeNumber to ("0" & episodeNumber) set episodeName to get name of aFile as string set episodeName to my findAndReplace(":", "", episodeName) # create the folders if needed tell application "Finder" set newPath to newLocation set tempPath to newPath & ":" & showName if not (exists folder tempPath) then make new folder at newPath with properties {name:showName} end if set newPath to tempPath set tempPath to newPath & ":Season " & seasonNumber if not (exists folder tempPath) then set tempName to "Season " & seasonNumber make new folder at newPath with properties {name:tempName} end if set newPath to newPath & ":" & "Season " & seasonNumber end tell set newName to episodeNumber & " - " & episodeName & "." & fileExtension as string end if if mediaType is movie then set newLocation to "BigBird:Movies" set movieTitle to get name of aFile as string set movieYear to get year of aFile set movieTitle to my findAndReplace(":", "", movieTitle) set newName to movieTitle & " - " & movieYear & "." & fileExtension set newPath to newLocation end if #skip if file is already correctly renamed if fileLocation is equal to newPath & ":" & newName then exit repeat # move the file tell application "Finder" move theFile to newPath set name of theFile to newName end tell set numberUpdated to numberUpdated + 1 end if end repeat end repeat display dialog "Updated and moved " & numberUpdated & " files" end tell on findAndReplace(tofind, toreplace, TheString) set ditd to text item delimiters set text item delimiters to tofind set textItems to text items of TheString set text item delimiters to toreplace if (class of TheString is string) then set res to textItems as string else -- if (class of TheString is Unicode text) then set res to textItems as Unicode text end if set text item delimiters to ditd return res end findAndReplace
You need to login to post a comment.
