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.

Possible Duplicate:
Watch Filesystem in Real Time on OS X and Ubuntu

I'm looking for a efficient method to monitor a local directory in OSX and if any files have been changed in that directory run a bash script to commit the files to github.

Any recommend tools for monitoring a directory for file changes, then triggering an action, i.e. a bash script?

share|improve this question

marked as duplicate by slhck, Nifle, Daniel Beck, 8088, Randolph West Jul 22 '12 at 2:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
This question as-is is borderline a software recommendation, which aren't generally allowed on Super User. Try rephrasing it to ask your root question, "How can I automatically commit changes and push from a git repo whenever files are added/deleted/changed?" –  Darth Android Jul 6 '12 at 21:47
    
@DarthAndroid, accd to the FAQ, this question is fine as it stands. The OP is not asking for shopping or buying advice. –  ephsmith Jul 6 '12 at 23:26
1  
@eph The OP is asking for recommendations for something, which is rather off topic. The main problem though is that they're not explaining their problem and only ask for their attempted solution. –  slhck Jul 6 '12 at 23:57
    
The problem is simple. Monitor a directory for changes and commit those changes to a repository. It's all in the OP's question. The link you provided has the answer. Good call. –  ephsmith Jul 7 '12 at 2:22

2 Answers 2

up vote 6 down vote accepted

Using fswatch from your repository:

fswatch . 'git commit -avm "snapshot at ${date}"'

This simple example would only catch changes to files already in the repository.

share|improve this answer
    
This can be done with folder actions which are built in to OS X. See the answer via the link that slhk provided above. –  ephsmith Jul 7 '12 at 2:20
1  
You could expand your answer by adding an example explaining what the OP wants to achieve. Just posting a link is not encouraged. –  slhck Jul 7 '12 at 8:18
    
This looks encouraging. I thinking I could run ./fswatch /some/dir ./some/dir/bash_script.sh –  Tegan Snyder Jul 9 '12 at 2:08
    
+1 - I tried fswatch after reading your answer. Excellent utility - very similar to inotify for linux and it makes use of OS X's native fsevent –  cwd Aug 28 '12 at 19:10

One option would be to just use launchd. Save a property list like this as ~/Library/LaunchAgents/com.superuser.445907.plist, and load it with launchctl load ~/Library/LaunchAgents/com.superuser.445907.plist or by logging out and back in.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.superuser.445907</string>
    <key>Program</key>
    <string>/Users/username/script</string> <!-- ~/ doesn't work -->
    <key>WatchPaths</key>
    <array>
        <string>/Users/username/Folder/</string>
    </array>
    <key>ThrotteInterval</key>
    <integer>0</integer> <!-- run at most every 0 seconds, by default 10 -->
</dict>
</plist>

Launchd only registers changes to files when they are saved atomically, or deleted and recreated every time they are saved. Most OS X applications perform atomic saves by default, but for example TextMate and vim don't. Changes in subfolders of watched folders aren't detected.

launchctl unload $path && launchctl load $path applies changes to a plist.

See man launchd and man launchd.plist for more information.

share|improve this answer
    
Interesting approach. I will take a look at it and get back to you. Thanks for the feedback. –  Tegan Snyder Jul 9 '12 at 2:08

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