Automate Your Mac with Folder Action Scripts

Do you repeatedly find yourself wanting to do something in the Finder with every file of a certain type? Perhaps you regularly download files from a particular website that come in with a .txt extension, even though they’re CSV files that should have a .csv extension? Or maybe you want to rename files according to their creation date whenever they’re moved into a specific folder? Or copy every file whose name matches a specific string to a remote file server?

Your desires will undoubtedly differ from everyone else’s, but the key to automating file-related actions in the Finder is a longstanding macOS technology called folder action scripts. In essence, you attach a custom AppleScript to a folder, and whenever the folder’s contents change, the script runs. Anything you can do with AppleScript, you can automate with a folder action script.

Don’t panic at the sight of the word “AppleScript.” Although creating a folder action script requires creating an AppleScript, we don’t expect you to write an AppleScript or even know much about it. You can get an AI chatbot like ChatGPT, Claude, or Gemini to write the actual code—all you need to do is explain what you want to the chatbot, copy and paste code into Script Editor, and link the script to the desired folder.

Two warnings: always start with test files in a test folder before letting a script work on real files in a real folder, and be doubly cautious about scripts that move files to the Trash.

Let’s get started! We’ll use the CSV renaming script as an example.

Step 1: Create a Script with AI Help

When working with an AI chatbot to write an AppleScript, it’s helpful to be as specific as possible. Here’s the prompt we started with:

Write an AppleScript that I can use to make a folder action script for my Downloads folder. I want it to detect a newly downloaded file that has a .txt extension and present me with a dialog with two buttons asking if I would like to change the filename extension to .csv (the default) or leave it as .txt.

Paste that into the chatbot of your choice, and it will return a script. Copy it to the clipboard—chatbots usually include a button to copy just the text of the script, so you don’t have to select it manually.

Step 2: Save Your Script

Now you need to turn that script into something functional. Follow these steps:

  1. Open Script Editor, which you’ll find in the Utilities folder in your Applications folder.
  2. Choose File > New to create a new script.
  3. Paste the text of the script from the chatbot into the script.
  4. Click the hammer icon in Script Editor’s toolbar to check for syntax errors. If there are none, the text turns from all purple to various colors, as shown below. (We’ll assume the script is correct for now; more on how to fix errors in Step 4 below.)
  5. Choose File > Save, and in the Save dialog, navigate to ~/Library/Scripts/Folder Action Scripts/ (that’s the Library folder in your user folder). If the Folder Action Scripts folder doesn’t exist within Scripts, press Command-Shift-N (while still in the Save dialog) to create a new folder. Be sure to name it exactly Folder Action Scripts.
  6. Still in the Save dialog, choose Script from the File Format pop-up menu and click Save to save the file.

Step 3: Connect Your Script to a Folder

To open the Folder Actions Setup app, you may be able to Control-click the desired folder (such as a Test folder on your desktop) and choose Folder Actions Setup from the pop-up menu; it might also be in a Services submenu. But the easiest way to open it is with Spotlight. Press Command-Space, type Folder Actions Setup (or enough of the name for Spotlight to find it), and press Return. Once you have the app open:

  1. Select the Enable Folder Actions checkbox at the top.
  2. Click the + button under Folders with Actions, and open the Test folder in the file dialog.
  3. Click the + button under Script, then select the script you just saved—the list is sorted alphabetically, so you may need to scroll.

A folder can have multiple folder action scripts linked to it, though be aware that they can interact with one another in unexpected ways. You can disable a script by deselecting its checkbox or remove it entirely by selecting it and clicking the – button. To make changes to a script, select it and click Edit Script to open it in Script Editor.

Step 4: Test Your Script

This is the moment of truth—did the chatbot get it right? Create a text file in TextEdit and save it on the desktop with a .txt extension. Then drag it into the Test folder and see if you’re prompted to rename it to .csv. If so, you’re done!

But what if it doesn’t work? What to do depends on how it failed:

  • Script Editor complains about syntax errors: Report the error to the chatbot by taking a screenshot like the one below and pasting or dragging it into the chatbot text entry field. It will analyze the screenshot to identify the error and try to provide you with revamped code that fixes the problem.
  • Nothing happens: First, verify that the folder action is enabled in Folder Actions Setup and that the correct folder is listed. Then return to the chatbot and say exactly that. “I dropped a .txt file in my Test folder, but nothing happened.” It will analyze the code it previously wrote and attempt to address whatever is causing it to fail.
  • You get a permissions request: The first time a folder action script runs, macOS may ask for permission to control the Finder or access certain folders. Click Allow when prompted.
  • You get some other error: Just as with code errors in Script Editor, your best bet is to take a screenshot of the error and paste it into your chat. Be sure to add any additional information that might shed light on the reason for the error.
  • The wrong thing happens: If something else happens, but it’s not what you want—like more files being acted on than you intended—go back to the chatbot and describe precisely what happened and how that was wrong, reiterating the results you want to achieve.

It’s not uncommon to go back and forth with the chatbot several times to end up with an AppleScript that works as you want. If you still have trouble, ask the chatbot to add debugging alerts that show you where the process breaks down.

Other Useful Folder Action Ideas

Once you’ve mastered the basics, consider these automation possibilities:

  • Automatically resize images added to a folder to specific dimensions
  • Sort downloaded files into subfolders based on file type
  • Add a timestamp or custom prefix to every file added to a project folder
  • Play a sound or send a notification when files matching certain criteria appear
  • Back up critical files by copying them to a second location whenever they’re added to a watched folder

There’s undoubtedly a DIY aspect to all this, but folder action scripts are both a practical use of AI chatbots and a relatively easy way to automate file-based workflows that are tedious or time-wasting when done by hand. If you’re attracted to the idea but uninterested in fussing with chatbots, Script Editor, and Folder Actions Setup, look into Noodlesoft’s Hazel, a $42 utility that provides an easy-to-use interface for automatically organizing files on your Mac.

(Featured image by iStock.com/Poca Wander Stock)


Social Media: Automate Mac file chores like moving, renaming, or tagging files with folder action scripts that run whenever files change. You can even get an AI chatbot to write the script for you.

Similar Posts

  • Droids, Drones, Scooters, Cars and USB C

    I remember only a couple years ago when drones were new and cutting edge technology. Now, there are huge sections of the show devoted to drones of all sorts: fighting drones, mini drones, paper airplane drones and dancing drones. I don’t know if it is the Star Wars influence but droids were everywhere, including “laundroids” for folding your laundry, grill cleaning droids, window washing droids and all kinds of robots.

    3D printers were new and unique and again whole sections of the show were devoted to “replicators” making everything from iPhone cases to clothing to spare body parts. Several companies were there just to show their filaments for these 3D printers.

    Scooters were everywhere. You know, the ones in the news that have the batteries that blow up. Well, literally dozens of companies were showing their versions and the original Segway had a booth, too. Some one-wheel scooters were there as well as shoes with wheels that zipped you around.

    p{text-align: center;}. !http://blog.smalldog.com/images/4638.jpg!

    Self-driving cars and technology for self driving cars dominated the North Hall and some concept cars were shown, too. My favorite was the Faraday electric car that looked like a single seat batmobile.

    USB-C made its debut at the show with hubs, cables and some USB display port displays, too. I think we will see a lot of USB-C stuff coming up!

    Less prevalent this year was the huge variety of iPhone and iPad cases. There were huge sections last time but while there were several companies showing cases it was toned way down. In their place, power banks of all sorts were being shown in every imaginable shape and size. The Apple battery case, aka the hump, was universally panned but several companies had slim battery cases for the iPhone.

    p{text-align: center;}. !http://blog.smalldog.com/images/4641.jpg!

    I did walk through the TV section but it was not as notable as in past years. The 3D fad has sort of expired and 4K displays are common. I still love the OLED displays, though.

    Other areas that were huge were health care and fitness with a lot of wearable fitness devices and health monitors or all sorts from implantable blood glucose devices to blood pressure cuffs, thermometers and scales. The home automation section was larger than previous years and there were some new HomeKit compatible devices. I liked the NoLok offering of bluetooth compatible padlocks and bike locks that work similar to the Kevo system.

    It was a quick trip out to Vegas but it was certainly worthwhile. I will follow up next week with a bit more.

  • Grace has tired of riding the little Vespa scooter so we are selling it. I bought an almost antique Victory cruiser so we both have bikes down here. I am going to Jasper, GA to pick it up this weekend and riding it back through the back roads of Georgia. It should be a nice little break.

    I am going to miss Johnny Dread and the reggae show down here but I am sure Grace will be there. It is hard to believe that we are heading into March already. My granddaughter, Gracie, is a Feb 29 baby so she is celebrating her 4th birthday as a 12-year old. My other granddaughter, Khadija, was off this week visiting colleges in the Boston area. Sure makes me feel old. I remember announcing Khadija’s birth here in Kibbles with the line “just call me gramps” and they still do!

    Thank you for reading this issue of Kibbles & Bytes!

    Your Kibbles & Bytes Team,

    _Don, Emily, Morgan & Hadley_

  • This is the craziest Presidential election cycle that I have seen. I first got involved when President Johnson was running against Barry Goldwater and that seemed pretty crazy especially after I lost faith with the President over Vietnam. But this time it would be great comedy if the stakes were not so serious. I have to tell you that seeing Donald Trump ask people to raise their hands in a pledge is one of the scariest things I have seen in a long time.

    Voting is so important and our system is messy with primaries, caucuses, super delgates and conventions but it is also the basis of our democracy. I am proud to say that the Vermont legislature passed an automatic voter registration bill unanimously this week, meaning when you get a driver’s license you are automatically registered to vote. You really do not have the right to complain about your leaders if you do not get out and vote. So, exercise your right and go to the polls when the circus comes to your state!

    Thank you so much for reading this issue of Kibbles & Bytes!

    Your Kibbles & Bytes Team,

    _Don, Emily & Hadley_