Folder Actions let you automatically run AppleScripts whenever items are added to, removed from, or modified in a specific folder. This can be useful for automating tasks such as processing exported files, uploading them to a server, or triggering notifications.
Step 1: Create the Folder Action Script
- Open Script Editor (found in /Applications/Utilities/).
- Create a new script with the following example code:
on adding folder items to this_folder after receiving added_items repeat with anItem in added_items display dialog "A new item was added: " & (name of (info for anItem)) end repeat end adding folder items to
- This simple example will display a dialog each time a new file is added to the folder.
In a real-world case, you would replace the display dialog line with the action you want to perform — for example, a command that uploads the file to a server or copies it elsewhere.
Step 2: Save the Script
- From Script Editor, choose File > Save.
- Set the File Format to Script.
- Save the script in: "/Library/Scripts/Folder Action Scripts/"
You may need administrator rights to save files in this folder.
⚠️ If you save the script elsewhere, it may not appear in the Folder Actions Setup utility.
Step 3: Attach the Script to a Folder
- Locate the folder that should trigger the action — for example, the folder where your application exports EPG files.
- Right-click (or Control-click) the folder and select: "Services > Folder Actions Setup..."
- In the Folder Actions Setup app:
- Ensure that Enable Folder Actions is checked.
- Select your target folder in the list on the left (you can add it using the + button if needed).
- Click the + button under the right-hand pane to attach your saved script to that folder.
Close the Folder Actions Setup window when done.
Your script is now active — macOS will automatically run it each time new files are added to that folder.
Step 4: Testing Your Folder Action
- Add a file to the monitored folder.
- You should see the script’s behavior triggered (for example, the dialog from the sample script).
If nothing happens:
- Verify that Folder Actions Setup has the folder listed and the checkbox beside it enabled.
- Make sure Folder Actions are globally enabled (top checkbox in the app).
- Check that Script Editor has permission to control your computer under System Settings > Privacy & Security > Automation.
- Try restarting Folder Actions Dispatcher by logging out and back in, or by running this command in Terminal:
killall Folder Actions Dispatcher
Optional: Editing or Removing Folder Actions
- To edit or remove a script, reopen Folder Actions Setup and adjust or delete it from the folder’s attached list.
- You can attach multiple scripts to the same folder — each will run when the event occurs.
Additional Notes
- Folder Actions only run when a user is logged in; they don’t execute in the background for all users.
- Scripts must be saved as .scpt files (compiled AppleScript), not plain text.
Folder Actions can respond to several types of events, such as:
- Adding items
- Removing items
- Opening or closing the folder
Comments
0 comments
Please sign in to leave a comment.