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.

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 2

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.

EDIT:

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

<?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.run-pdflatex</string>
    <key>OnDemand</key>
    <true/>
    <key>Program</key>
    <string>/Users/foo/run-pdflatex.sh</string>
    <key>ProgramArguments</key>
    <array>
            <string>run-pdflatex.sh</string>
    </array>
    <key>WatchPaths</key>
    <array>
            <string>/Users/foo/doc.tex</string>
    </array>
    </dict>
</plist>

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

 
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.