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

  • The airshow returns to Key West this weekend after a few years absence. It should be fun to go see the planes, the Blue Angels and other stunt pilots.

    We have gotten stock of the new 9.7-inch iPad Pro so stop into one of our stores if you want to get a hands-on look at the latest from Apple!

    Thank you for reading this issue of Kibbles & Bytes!

    Your Kibbles & Bytes Team,

    _Don, Emily & Hadley_

  • Hey Dora…

    So we have Siri and I’ve been playing around with Alexa (don’t tell Grace!) but now I have Dora, too. Dora is the computer from Robert Heinlein’s Time Enough for Love, The Number of the Beast, The Cat Who Walks Through Walls which were some of my favorite Sci-Fi as a kid.

    I was helping a customer that has pretty bad arthritis and struggled to use the keyboard. I was straightening out her email and getting her off of AOL (something we do often!) and noticed how difficult it was to type a simple email. So, I showed her dictation on the Mac and wow, it was like a light just got switched on. Dictation has come a long way and if your are on Mavericks, Yosemite or El Capitan, Apple’s enhanced dictation works wonderfully.

    Dictation will not be a satisfying experience for you if you have a lot of noise in the room, i.e. other people talking, music, etc, but if you are working alone in a relatively quiet environment it can be a great tool not only for dictating that email but you can also use spoken commands to direct your Mac to take action.

    Setting up Enhanced Dictation

    * Open System Preferences, then click on Dictation & Speech. Turn on Dictation and set up your options.

    * Click *Use Enhanced Dictation*. This will download a 1.2GB file so that you can dictate without internet connection.

    * Choose your language and dialect. Some languages, such as English, have multiple dialects.

    * Choose the keyboard shortcut you will use to signal that you’re ready to start dictating. The default is pressing the function Fn key twice, which I find convenient but you can customize it.

    * Choose your preferred microphone from the pop-up menu below the microphone icon. Normally, you use the internal microphone but if you are using a headset or external microphone you can choose that.

    Using Dictation

    * Go to a document or other text field and place the insertion point where you want your dictated text to appear.

    * Press the keyboard shortcut for starting dictation. The default shortcut is Fn Fn (press the Fn key twice). Or choose Edit > Start Dictation. When your Mac is listening, it displays a microphone with an input meter that rises and falls as you speak.

    * Speak the words that you want your Mac to type. Use dictation commands to add punctuation, formatting, and more.

    * To stop dictating, click Done below the microphone icon, or press Fn, or switch to another window.

    The more you use Dictation, the better it understands you. Dictation learns the characteristics of your voice and adapts to your accent.

    I will go into some of the more enhanced features like Dictation Commands in next week’s Kibbles & Bytes but I can tell Dora to Open an App, select text, move up or down and much more. I think you will like dictation on the Mac, give it a try!

  • Backups: Trust but Verify

    It’s easy to assume your backup app—whether it’s Time Machine, Carbon Copy Cloner, Backblaze, Retrospect, or something else—is quietly doing its job. But…

  • Black History Month – Thurgood Marshall

    Way before Barack Obama broke the color barrier to become president of the USA, Thurgood Marshall broke that barrier for another of the most powerful and important positions in the country, that of Supreme Court Justice. After graduating from high school with honors he applied to the University of Maryland law school where he was not accepted because he was black. Instead, he went to Howard University and received his law degree in 1933.

    Before being appointed Supreme Court Justice, he had a stellar career from 1934 to 1961 as a lawyer for the NAACP where he won landmark civil rights cases. Beginning in 1940, Marshall won 29 of 323 US Supreme Court cases. One of his first big cases was Smith vs. Allwrite in 1944 which overthrew the South’s “White Primary”. The White Primary was a practice of excluding African Americans from the Democratic Party. It was most common in a state where that party controlled the state government.

    In 1954 Marshall achieved a landmark victory with the case of Brown vs. Board of Education of Topeka. This Supreme Court decision demolished the legal basis for segregation in the USA. It also made state-enforced racial segregation in public schools invalid.

    In 1961 he was appointed the the US Court of Appeals by President Kennedy. He was the first African American on the Court of Appeals and went on to be appointed to the Second Court of Appeals. President Johnson made him the Solicitor General in 1965 and later in 1967 President Johnson nominated him for the Supreme Court.

    On the Supreme Court he was a steadfast supporter of positive gender and racial action policies and in his 24 years on the court he became a vocal liberal on a conservative-dominated court. He was an ardent supporter of Constitutional protection of individual rights, in particular the rights of criminal suspect versus the government. Marshall’s backing of Affirmative Action led to his strong dissent in the Regents of the University of California vs. Blake in 1978. Justice William Brennan was Marshall’s most reliable confederate who voted with him against the death penalty.

    Citing poor health, Thurgood Marshall stepped down from the court in 1991 and remained a vocal critic of the court until his death in 1993 at the age of 84.