I've never written a script for OS X, and I don't really know which scripting tool i'll use for this task.

Here's a pseudo code for the script I want to build :

whenever a new file X is added to the directory D do:
copy X 
paste X to the directory B

I don't want someone to code this for me, I want to know what tool (language maybe) should I use to write this script, and how to make OS X runs it whenever the event occurs.

I don't know what to tag this. Please contribute. Please redirect if this isn't the right forum for this question.


Very simple using Automator & Folder Actions.

  • Make a new Folder Action, then set the source to Folder A
  • select a Finder action from the left column,
  • drag 'Copy Finder Items' from the centre to the right
  • set the destination to Folder B.
  • Give it a name & save.

enter image description here

Every time anything is added to A it will automatically copy to B.

  • 3
    And if you want to do something more complicated, Automator has a 'Run Shell Script' action which you can use with a number of shell script variations, Ruby, Perl, and Python. If you go down this route, I'd advocate sticking with sh/bash or whichever language with which you are most comfortable. Mar 24 '16 at 9:07
  • 1
    I've found there to be a bug in this simple Automator Action in that if a file already exists in A and you answer Replace, it doesn't get copied to B. This was tested under OS X 10.8.5 and might not be an issue in other versions of OS X. Mar 25 '16 at 2:30
  • Thanks! I had to also right click on the folder in the Finder and click "Folder Actions Setup" > "Run Service" > add the action to the folder there. (macOS 11.6)
    – shim
    Oct 5 '21 at 15:56

I can only think of two ways that require (free) third party packages:

1st. A package called watchdog por monitoring file system events and triggering actions. It's actually a python package, but it also includes a shell utility so you can create scripts from the terminal without actually coding.

2nd. use a small program called fswatch which uses Mac OS's File System Events API to monitor your files and folders, and can trigger scripts.

They both require you installing the package/program, and seem to do what you require. Hope this at least points you in the right direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .