6

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.