Folder Actions are one of many hidden gems in macOS. You can set an action to occur whenever the contents of a folder are changed. This can be a simple action drawn from a list that Apple provides with macOS, an AppleScript, or a workflow produced in Automator. Automator lets you extend these actions into Terminal shell scripts and other languages.
You can use Folder Actions for a lot of disparate purposes:
Control-click any folder in the Finder and choose Services > Folder Actions Setup in Monterey. In early versions of macOS, the option appears in the main lists of contextual items. To avoid the malicious and accidental installation of Folder Actions, macOS requires a confirmation step that can’t be automated: click Run Service in the Confirm Service dialog. This adds the current folder to the Folders with Actions list without adding actions.
The Folder Actions Setup window appears with a dialog already open that reads Choose a Script to Attach. This list includes ones that Apple seeded, locating them inside the /Library/Scripts/Folder Actions Scripts
folder. Any scripts installed by apps or that you’ve created and placed inside your Home directory’s ~/Library/Scripts/Folder Actions Scripts
folder appear as well.
Folder Actions Setup shows all folders macOS is watching. Select any folder to see which scripts are attached. You can use checkboxes to toggle scripts on or off and folder watching for each folder on or off.
You can create Folder Actions in a numbers of ways:
AppleScript is relatively easy to write and can be adapted from simple recipes. Apple offers some in its developer documentation of the feature. I also recommend reading Jessica Thornsby’s article.
You can use AppleScript as a simple bit of connective tissue, too. For instance, I have a workflow in Flying Meat’s Retrobatch Pro image-processing software that puts a border around an image. A simple AppleScript turns a folder into a spring-loaded passthrough for the Retrobatch Pro operation.
If you need more sophisticated watched-folder behavior, turn to Hazel from Noodlesoft, a supercharged third-party version of Folder Actions.
We’ve compiled a list of the questions we get asked most frequently, along with answers and links to columns: read our super FAQ to see if your question is covered. If not, we’re always looking for new problems to solve! Email yours to mac911@macworld.com, including screen captures as appropriate and whether you want your full name used. Not every question will be answered, we don’t reply to email, and we cannot provide direct troubleshooting advice.
Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our affiliate link policy for more details.
Glenn Fleishman’s most recent books include Take Control of Untangling Connections, Take Control of Your M-Series Mac, and Take Control of Securing Your Mac. In his spare time, he writes about printing and type history. He’s a senior contributor to Macworld, where he writes Mac 911.
Nenhum comentário:
Postar um comentário