I would like to have a folder action process subfolders.
This is my folder Structure:
¢ TV Shows
¢ /Grey’s Anatomy
¢ /Season 01
1. Grey’s Anatomy - s01e01.avi
2. Grey’s Anatomy - s01e02.avi
3. Grey’s Anatomy - s01e03.mp4
¢ /Season 02
1. Grey’s Anatomy - s02e01.avi
2. Grey’s Anatomy - s02e02.mkv
3. Grey’s Anatomy - s02e03.m4v
¢ /Heroes
¢ /Season 02
1. Heroes - s02e05-e08.mkv
¢ /Season 04
1. Heroes - s04e01-e02.mkv
2. Heroes - s04e03.mkv
I add the TV Show Folders( Grey’s Anatomy, Heroes, etc) and the Seasons (1 to 10). I have hazel move the TV Show file (ie S01e01.avi) to the right folder. I want to add the script below to the TV Show folders as a folder action to rename the file to its appropriate show name.
set _names to {}
set _unique to {}
set _duplicates to {}
tell application “Finder”
—defining TV FOLDERS
set TV_Folder to folder (choose folder)
--iterate through TV SHOW FOLDERS
repeat with SHOW_Folder in TV_Folder
set showfolder to name of SHOW_Folder
set a to length of showfolder
set b to length of " S99E99"
set c to length of " S99E98-E99"
--iterate through TV SHOW FOLDERS
set SEASON_Folders to every folder of SHOW_Folder
repeat with SEASON_Folder in SEASON_Folders
--get every filename and every extension
set _filenames to name of every file of SEASON_folder
set _extensions to name extension of every file of SEASON_folder
repeat with n from 1 to count of _filenames
--creates FILE NAME AND FILE EXTENSION
set _filename to item n of _filenames
set _extension to item n of _extensions
--creates _names
if _filename contains "-E" then
set _filename to (text 1 thru (a + c) of _filename & "." & _extension) as string
else
set _filename to (text 1 thru (a + b) of _filename & "." & _extension) as string
end if
get _filename
set end of _names to _filename
--creates _unique and _duplicates
repeat with x from 1 to count of items of _names
set n to item x of _names
if n is not in _unique then
set end of _unique to n
else
set end of _duplicates to n
end if
end repeat
--deletes _duplicates
repeat with theitem in _duplicates
if theitem is not equal to "" then
delete (every file of entire contents of SEASON_Folder whose name is theitem)
end if
end repeat
set filelist to every file of SEASON_Folder
repeat with CurrentFile in filelist
--creates FILE NAME AND FILE EXTENSION
set CurrentFName to (the name of CurrentFile)
set CurrentFExtension to (the name extension of CurrentFile)
--changes file names
if CurrentFName contains "-E" then
set _filename to (characters 1 thru (a + c) of CurrentFName & "." & CurrentFExtension) as string
set name of CurrentFile to _filename
end if
if CurrentFName does not contain "-E" then
set _filename to (characters 1 thru (a + b) of CurrentFName & "." & CurrentFExtension) as string
set name of CurrentFile to _filename
end if
end repeat
end repeat
end repeat
end repeat
end tell