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.
First, download watchpaths and place it somewhere in your path. I use ~/bin, so try something like this:
cd ~/bin wget https://github.com/iandennismiller/watchpaths/raw/master/bin/watchpaths.py chmod 755 ~/bin/watchpaths.py
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:
watchpaths.py "rsync -a ~/my_pictures email@example.com:public_html" ~/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.”
The project page, including links for downloads, is here. If there is any interest, I am happy to incorporate feedback.