Folder Action to Add Files to Year/Month Folders
So now that I'm a Playlist XML exportin' maniac, I created a Folder Action to automatically file the exports to my "Playlist Exports" folder into Year/Month folders, according the date of save. Here it is. When a file is added to the folder the script is attached to, it moves it to a newly-created or existing Year/Month hierarchy:
on adding folder items to thisFolder after receiving theseItems
repeat with anItem in theseItems
tell me to processThis(anItem, thisFolder)
end repeat
end adding folder items to
to processThis(anItem, thisFolder)
set yearMonthPath to (do shell script "date '+%Y:%m_%b'") as text
-- Y=year, m=month number (for sorting), b=month abreviation. eg, 2025:06_Jun
try
set folderPath to (thisFolder & yearMonthPath) as text
tell application "Finder"
try
exists folder (folderPath as POSIX file as alias)
on error
do shell script "mkdir -p " & quoted form of POSIX path of (folderPath as text)
end try
move anItem to folder folderPath with replacing
end tell
end try
end processThis

