Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm developing a web project using some libraries that force me to launch a shell command to compile some files everytime i modify them.

This task is obviously tiresome and i'm looking to find some script to handle it (I'm on OSX).

Is there a way to automatically launch a shell script when content of a given directory (+subdirs) is changed?

share|improve this question
2  
This depends on your operating system. On Linux, use inotifywait (see e.g. superuser.com/questions/181517/…). –  Gilles Aug 30 '10 at 7:03

3 Answers 3

up vote 5 down vote accepted

Mac OSX has two filesystem notification APIs: kqueue and FSEvents. I don't know about commands that give you access to them without programming. There is a python binding for FSEvents.

See also View Filesystem Access in Real Time on Mac OS X.

Given what you're trying to do, you might want to try a different approach: rather than trigger a recompile when the source files have been modified, trigger a recompile when the compiled files are requested (using make, so that nothing is actually recompiled if the source files haven't changed). This may be too costly if you have to do this for every request to a web site, though; benchmark to find out.

share|improve this answer
1  
I used the python bindings for FSEvents and it worked (gist.github.com/558970), thanks! –  systempuntoout Aug 31 '10 at 12:55

The BSD command wait_on based on kqueie is available in MacPorts, it provides just what you need.

The wait_on command allows shell scripts to access the facilities provided by kqueue(3). This allows scripts to detect files being added to directories, data appended to files and many other things - all without polling.

In Linux I would use incron, INotify Cron.

share|improve this answer

Not really, but you can get close. You can write a script that checks to see if the files in a directory have changed (probably by checking them against a file somewhere), and if so, build them.

Then, you can set cron to run this script every 10 minutes, so you know your stuff is no more than 10 minutes old.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.