Take the 2-minute tour ×

Anyone know about a program for Mac OS that you can pass the name to an executable and a file to watch, so that it then runs the executable everytime the file being watched changed?

I have something like this in mind:

$ fwatch /Users/foo/doc.tex /Users/foo/run-pdflatex.sh &
  fwatch running. Listening for changes in /Users/foo/doc.tex.
$ echo "This aint no LaTeX" > doc.tex
$ fwatch: Change in /Users/foo/doc.tex detected. Running /Users/foo/run-pdflatex.sh...
share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

You can set this up using launchd. Specifically, you need to use the watchpaths key in your launchd plist to look for changes in that file.

Exhaustive information available in this AFP548 article.

Although it appears it's no longer under development, Lingon is an application providing a GUI way to set up these launchd plist files.


Roughly, here's what you'd do using your sample paths above. Save a file named com.superuser.run-pdflatex.plist with the following contents to ~/Library/LaunchAgents

<plist version="1.0">

Then you'd type launchctl load ~/Library/LaunchAgents/com.superuser.run-pdflatex.plist in the terminal to load your file-watching daemon.

Above is untested, but that's the general idea.

share|improve this answer
add comment

You can do it in Automator. It is under Folder Option in the automator workflow I believe (not in front of a Mac). Then you just attach the script to the folder and it will fire every time a file is added/changed.

share|improve this answer
I can't quite follow. I'm new to Automator, but as far as I know you can't choose when to execute your script but only what to do when it is run. There's the folder actions in Mac OS that I could use also but I figured AppleScript only has the action "on adding folder items to" but nothing like "on changing folder items in". –  Johannes Jul 15 '10 at 16:22
You are correct @Johannes. While there are folder actions for adding folder items, removing folder items, moving the folder window, closing the folder window, and opening the folder, there is no Folder Action for detecting changes to files. You can see this by opening the StandardAdditions.osax dictionary in Applescript Editor. –  ghoppe Jul 15 '10 at 17:09
add comment

Your Answer


