Mac maintenance
Mac Folder Actions: Automating Cleanup as Files Arrive
Set up Folder Actions on Mac to automatically organize, sort, or clean up files the moment they arrive. Practical recipes for Downloads, Desktop, and more.
Folder Actions are one of those macOS features that’s been around since Mac OS X 10.2 and most people have never heard of them. They run a script every time something changes in a folder you’ve attached them to. New file in Downloads? Run a script. File deleted from Desktop? Run a script.
It’s the closest thing macOS has to automatic cleanup that doesn’t need third-party software. Set up well, your Downloads folder organizes itself.
What Folder Actions can do
Three kinds of triggers:
- A new item is added to the folder
- An item is removed from the folder
- The folder window is opened or closed
For each trigger you attach an AppleScript or Shortcut. The script gets the list of items that triggered it and can do whatever AppleScript can do — move files, rename them, run shell commands, send notifications.
Useful in practice:
- Auto-sort Downloads by file type
- Tag screenshots with a Finder color
- Compress folders dropped into a “compress” folder
- Delete files older than 30 days when a folder is opened
- Rename screenshots from “Screenshot 2025-01-15 at 3.42.11 PM.png” to date-only
You can chain these: a new screenshot lands on the Desktop, gets renamed, moved to ~/Pictures/Screenshots/, tagged with a color. All without you doing anything.
Setting one up
The approach changed slightly in macOS Sonoma. Now:
- Open Script Editor (in
/Applications/Utilities/) - File → New to create a new script
- Save it to
~/Library/Scripts/Folder Action Scripts/— create the folder if it doesn’t exist - In Finder, right-click the folder you want to attach to → Quick Actions → Folder Actions Setup
- Tick “Enable Folder Actions” if it’s not already on
- Pick your script
Or do it from the Folder Actions Setup app directly (it’s in /System/Library/CoreServices/).
You’ll be prompted to allow Script Editor / System Events to access the folder. Approve it. macOS won’t run the script otherwise.
Make cleanup automaticSweep does the routine cleanup so you can stay in your work. Get Sweep free →
Recipe 1: Sort Downloads by file type
The Downloads folder is most people’s biggest mess. This script moves files to subfolders based on their extension.
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application "System Events"
set fileExt to name extension of anItem
end tell
set targetFolder to ""
if fileExt is in {"jpg", "jpeg", "png", "gif", "heic", "webp"} then
set targetFolder to "Images"
else if fileExt is in {"mp4", "mov", "avi", "mkv"} then
set targetFolder to "Videos"
else if fileExt is in {"pdf"} then
set targetFolder to "PDFs"
else if fileExt is in {"zip", "dmg", "pkg"} then
set targetFolder to "Installers"
else if fileExt is in {"mp3", "wav", "m4a", "flac"} then
set targetFolder to "Audio"
end if
if targetFolder is not "" then
tell application "Finder"
set destPath to (folder of thisFolder as text) & (name of thisFolder as text) & ":" & targetFolder
if not (exists folder destPath) then
make new folder at thisFolder with properties {name:targetFolder}
end if
move anItem to folder destPath
end tell
end if
end repeat
end adding folder items to
Save as Sort Downloads.scpt. Attach to your Downloads folder. New images go to Downloads/Images/, videos to Videos/, etc. Anything not in the list stays in the root, which is intentional — those are the files you probably want to triage manually.
Recipe 2: Auto-rename screenshots
Default screenshot names are ugly. This renames them to YYYY-MM-DD-HHMMSS.png.
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application "System Events"
set fileName to name of anItem
end tell
if fileName starts with "Screenshot" then
set timestamp to do shell script "date +'%Y-%m-%d-%H%M%S'"
set newName to timestamp & ".png"
tell application "Finder"
set name of anItem to newName
end tell
end if
end repeat
end adding folder items to
Attach to wherever you save screenshots — Desktop by default, or change the location in System Settings → Keyboard → Keyboard Shortcuts → Screenshots.
Recipe 3: Auto-tag files in a project folder
If you label files by project status with Finder tags, this script can apply tags automatically based on filename keywords.
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application "System Events"
set fileName to name of anItem
end tell
set tagsToAdd to {}
if fileName contains "DRAFT" then
set end of tagsToAdd to "Yellow"
end if
if fileName contains "FINAL" then
set end of tagsToAdd to "Green"
end if
if fileName contains "review" then
set end of tagsToAdd to "Orange"
end if
if (count of tagsToAdd) > 0 then
tell application "Finder"
set label index of anItem to (item 1 of tagsToAdd)
end tell
end if
end repeat
end adding folder items to
Yellow drafts, orange in review, green when final. Visible at a glance in Finder.
Recipe 4: Compress and remove
A “Compress me” folder that zips anything dropped in, then deletes the original.
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application "System Events"
set itemPath to POSIX path of anItem
set itemName to name of anItem
end tell
set zipPath to itemPath & ".zip"
set parentFolder to do shell script "dirname " & quoted form of itemPath
do shell script "cd " & quoted form of parentFolder & " && zip -r " & quoted form of (itemName & ".zip") & " " & quoted form of itemName
do shell script "rm -rf " & quoted form of itemPath
end repeat
end adding folder items to
Drop a folder of photos in, get back a zip. Useful for sending things or archiving large directories.
Recipe 5: Run on folder open — clean old downloads
This one fires when you open the Downloads folder. Moves anything older than 30 days to an archive subfolder.
on opening folder thisFolder
set folderPath to POSIX path of (thisFolder as alias)
do shell script "mkdir -p " & quoted form of (folderPath & "Old")
do shell script "find " & quoted form of folderPath & " -maxdepth 1 -type f -mtime +30 -exec mv {} " & quoted form of (folderPath & "Old/") & " \\;"
end opening folder
Open Downloads, anything more than 30 days old slides into Downloads/Old/. The folder stays scannable; nothing gets deleted automatically.
Shortcuts vs AppleScript
You can also use Shortcuts as folder actions in Sonoma+. In Shortcuts, create a new shortcut, set its input type to “Files,” then attach it via Folder Actions Setup or the Quick Actions menu.
Shortcuts is friendlier for simple tasks (move, rename, tag) but less flexible for anything requiring shell commands or conditional logic. AppleScript wins for complex flows.
A reasonable rule: if Shortcuts can do it in 5 actions or fewer, use Shortcuts. Otherwise, AppleScript.
Debugging
When a Folder Action fires and something goes wrong, the error rarely surfaces. To debug:
- Open Console.app and filter for “applescript” to see errors
- Run the script manually in Script Editor first to confirm logic
- Use
display dialog "got here"for quick checks - Check System Settings → Privacy & Security → Automation to confirm Script Editor / System Events have permission to access folders
If a script fires repeatedly or seems “stuck,” temporarily disable Folder Actions: right-click any folder, Quick Actions → Folder Actions Setup, untick “Enable Folder Actions.”
Limits and reality check
Folder Actions are good but not perfect. Things to watch:
- They don’t fire while the folder is being indexed by Spotlight
- They can be slow to trigger after sleep — sometimes 30+ seconds
- AppleScript itself is fragile across macOS upgrades
- Some apps save files in ways that bypass Folder Actions entirely
For mission-critical automation, native tools like Hazel or scheduled scripts via launchd are more robust. For “make my Downloads folder less of a swamp,” Folder Actions are perfect, free, and built in.
A reasonable starting point
Don’t try to automate everything. The two scripts most worth setting up:
- Sort Downloads by file type
- Rename and move screenshots
That’s enough to keep the two messiest folders in line. Add more recipes as you find specific friction in your workflow. The point isn’t elaborate automation — it’s removing 5 minutes of file shuffling per day, which adds up to half a workweek per year.