Imagine you are working on a set of files on your computer, and each time you change one of those files, you want to run a program to process the files again. This comes up all over the place, whether it’s software development, statistics, image processing, or lots of other domains. Recently, I was editing some source code, and each time I changed a file, I wanted to run a series of tests to make sure everything still worked. I made this process automatic with the help of a really handy utility called watchpaths.

Installing watchpaths

First, download watchpaths and place it somewhere in your path. I use ~/bin, so try something like this:

cd ~/bin
chmod 755 ~/bin/

Using watchpaths

Let’s say I want to monitor a folder containing images, and each time a new image is added I want to sync the folder to a remote computer. Using watchpaths, that will look like: "rsync -a ~/my_pictures" ~/my_pictures

To convert that command into English, it would sound like this:

“Watch the my_pictures folder for any changes (new files, deleted files, updated files, etc) and each time a change happens in that folder, synchronize the contents of that folder with my web server.”

More Information

The project page, including links for downloads, is here. If there is any interest, I am happy to incorporate feedback.