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

  • A Swinging Hot Spot in Paradise

    You are visiting Key West, accompanied by your trusty iPhone and MacBook Air. Suddenly there’s an emergency at work, and you need to get online with your Mac. You can pick up a cell signal with the iPhone, but there’s no Wi-Fi that isn’t locked up. Well, my first thought might be “oh well, I’m on vacation!” but you are dedicated and need to be online.

    Don’t worry! You can use your iPhone’s cellular data plan to create a personal Wi-Fi hotspot that lets your Mac access the Internet through your iPhone. Also called “tethering,” it’s fast, easy, and can be a life-saver when you just have to get online with a Mac or your Wi-Fi-only iPad. It supports up to 5 users, too, which means you can get your team online, too!

    Before we explain how to do set up a personal hotspot, note that most but not all cellular carriers allow tethering on existing plans. For some, you might have to pay more for tethering. Keep in mind that any data consumed by your Mac while tethered will count against your data allowance and may generate overage fees. Carriers with “unlimited” data, like T-Mobile and Sprint, generally throttle your bandwidth to slower speeds if you use too much data.

    Along those lines, if you use a file sharing service like Dropbox or Google Drive, or an Internet backup service like CrashPlan or Backblaze, turn them off before connecting. Particularly if they haven’t connected in a while, those services can transfer a lot of data quickly, which could result in a hefty overage charge or awkward data throttling for the rest of the month.

    With those warnings out of the way, follow these steps in iOS 9 to turn on Personal Hotspot:

    1. On your iPhone, if you’ve never enabled the feature before, go to Settings > Cellular > Personal Hotspot. Once you’ve turned Personal Hotspot on once, it moves up a level, so you can access it from Settings > Personal Hotspot.
    1. Tap on Wi-Fi Password and enter a password that’s at least 8 characters long and easy to type. It doesn’t need to be super secure because you can keep Personal Hotspot turned off unless you’re using it. But you do want a password so random people nearby can’t connect and use your data.
    1. Once you’ve entered a password, slide the Personal Hotspot switch.

    That’s it! The Personal Hotspot screen provides basic instructions for connecting to the iPhone via Wi-Fi, Bluetooth, and USB. Stick with Wi-Fi, since it’s the easiest and most reliable in most cases.

    • To connect to your new Personal Hot Spot on your Mac, click the Wi-Fi icon in the menu bar and choose your iPhone’s name.
    • On your iPad, go to Settings > Wi-Fi and choose your iPhone.
    • Enter your password when prompted, making sure to select Remember This Network. That way, you won’t even have to enter your password the next time.
    • The Mac or iPad then connects to your iPhone, showing a hotspot icon instead of the usual wave icon for the Wi-Fi menu.

    Could it get any simpler? When you’re done, the safest thing to do, to ensure you don’t accidentally end up using too much of your data allowance, is to turn off the Personal Hotspot switch in Settings > Personal Hotspot. Your Mac or iPad will automatically disconnect.

    Actually, it CAN be simpler! Your Mac can automatically use the personal hotspot on your iPhone to connect to the Internet when they’re within range of each other.

    Use Instant Hotspot on your iPhone (with iOS 8 or later) to provide internet access to your Mac computers and other iOS devices (with OS X Yosemite or iOS 8) that are in range and signed into iCloud using the same Apple ID. Instant Hotspot uses your iPhone — you don’t have to enter a password or even turn on Personal Hotspot.

    Make sure your iOS device and your Mac are signed into iCloud with the same Apple ID.

    On your Mac, click the Wi-Fi status icon in the menu bar, then choose your iPhone or iPad.

    After you connect to the iPhone or iPad Personal Hotspot, you can check the cellular signal strength and the battery status of the iPhone or iPad in the Wi-Fi status menu.

    When you’re not using using the hotspot, your devices automatically disconnect to save battery life.

    One more big advantage of Personal Hot Spots. When you are shopping for that new iPad, perhaps you don’t need the cellular model if you nearly always have your iPhone handy. That’s what I do. If I need internet access on my Wi-Fi iPad, I simply connect to my Hot Spot! Saves me the added cost of a cellular-enabled iPad and the monthly fees from the cell carrier!

  • Holiday Guide for People with Everything

    Shopping for the people who “already have everything” is kind of our hobby. Here are a few of the personalities we see all…

  • Never Paste Unknown Text into Terminal!

    Here’s a new scam to watch for. A client reported running across a suspicious website masquerading as a human verification test. Instead of…