Monitor a directory for changes and run a shell command, using OS X's FSEvents API
Pull request Compare This branch is 875 commits behind emcrisostomo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a small program using the Mac OS X FSEvents API to monitor a directory. When an event about any change to that directory is received, the specified shell command is executed by /bin/bash.

If you're on GNU/Linux, inotifywatch (part of the inotify-tools package on most distributions) provides similar functionality.


You need to be on Mac OS X 10.5 or higher with Developer Tools installed. Then, run make. Copy the resulting fswatch binary to a directory on your $PATH.

Basic Usage

./fswatch /some/dir "echo changed" 

This would monitor /some/dir for any change, and run echo changed when a modification event is received.

In the case you want to watch multiple directories, just separate them with colons like:

./fswatch /some/dir:/some/otherdir "echo changed" 

Usage with rsync

fswatch can be used with rsync to keep a remote directory in sync with a local directory continuously as local files change. The following example was contributed by Michael A. Smith:


# Keep local path in sync with remote path on server.
# Ignore .git metadata.

cd "$local" &&
fswatch . "date +%H:%M:%S && rsync -iru --exclude .git --exclude-from=.gitignore --delete . $remote"


This code was adapted from the example program in the FSEvents API documentation.