Skip to content

Monitor a directory for changes and run a shell command, using OS X's FSEvents API

Notifications You must be signed in to change notification settings

unphased/fswatch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fswatch.c

I have made modifications to the original program

My version does not fork a process. It writes out lines on stdout that provide information about changed files. This is a lot more precise and informative.

Original readme follows.

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.

Compile

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:

#!/bin/sh

##
# Keep local path in sync with remote path on server.
# Ignore .git metadata.
#
local=$1
remote=$2

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

About

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

About

Monitor a directory for changes and run a shell command, using OS X's FSEvents API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 100.0%