Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launchd: WatchPaths will not trigger simple "hello world" script (OS X 10.8)

having a strange issue here. I have ~/Library/LaunchAgents/com.me.helloworld.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.me.helloworld</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/me/temp/test.sh</string>
        </array>
        <key>WatchPaths</key>
        <array>
                <string>/Users/me/temp/Journal.txt</string>
        </array>
</dict>
</plist>

The idea is, if ~/temp/Journal.txt is modified, it should execute ~/temp/test.sh. test.sh has the following contents:

#!/bin/bash
echo "hello world from test.sh" >> itchanged.txt

So, if I change Journal.txt, I should get a file called itchanged.txt. When I do the following:

$ launchctl unload ~/Library/LaunchAgents/com.me.helloworld.plist
$ launchctl load ~/Library/LaunchAgents/com.me.helloworld.plist
$ touch Journal.txt

Doing an ls shows that test.txt is not created. However, if I manually do a ./test.sh, then itchanged.txt IS created. So the problem seems to be somewhere in recognizing that Journal.txt is changed and executing the script when this happens.

I am using OS X Mountain Lion. Any ideas?

like image 365
user1940620 Avatar asked Jan 01 '13 06:01

user1940620


1 Answers

Your script doesn't specify a path for itchanged.txt; since the default working directory for launchd-started processes is /, and your account probably doesn't have permissions to create files there, itchanged.txt will not ever be created. You should either specify a path in the script, or add the WorkingDirectory key to your .plist to change the default.

like image 104
Gordon Davisson Avatar answered Sep 21 '22 22:09

Gordon Davisson