brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Folder Actions run an AppleScript when new items land in a Finder folder

Finder
~/tips/tip-finder-folder-actions-script

on adding folder items to theFolder after receiving theNewItems

Attach a script to a folder so new arrivals are handled automatically.

A watched folder is an old Mac trick that still works: drop something in, and a script takes care of it. Apple calls it Folder Actions.

Write a script with a folder action handler. This one posts a notification with the number of new items:

on adding folder items to theFolder after receiving theNewItems
    display notification ((count of theNewItems) as text) & " new item(s)" with title "Inbox"
end adding folder items to

Save it in Script Editor as a compiled script in ~/Library/Scripts/Folder Action Scripts/. Apple’s Mac Automation Scripting Guide names that folder for your own scripts, and /Library/Scripts/Folder Action Scripts/ for all users.

Then connect it: Control-click the folder in Finder and choose Folder Actions Setup, pick the script and click Attach. Make sure Enable Folder Actions is ticked and the folder is switched on. If the menu item is hard to find, the Folder Actions Setup app lives in /System/Library/CoreServices/Applications.

Other handlers exist for items removed from the folder and for its window opening, closing or moving. Real uses I’d consider: converting screenshots dropped in a folder, or moving finished downloads to the right place.

The guide’s own example has a good habit in it: move each processed item somewhere else, so it isn’t processed again. And keep the script quick; a heavy job is better off in a separate script that the folder action starts.

Further reading: Watching Folders, Mac Automation Scripting Guide (Apple)

More Finder tips Option-Command-Y Quick Actions in the Finder preview pane rotate images and make PDFs Shift-Command-P show or hide the Preview pane Command-Up Arrow open the enclosing folder click the Trash in the Dock All Finder tips (37) All topics

Link