dougscripts.com

December 2 2025 - 3:14 pm

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

Site contents © 2001 - 2025 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.