这里有一个奇怪的问题。我有一个文件路径为~/Library/LaunchAgents/com.me.helloworld.plist,其内容如下:
<?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>
这个想法是,如果~/temp/Journal.txt被修改了,就会执行~/temp/test.sh。test.sh的内容如下:
#!/bin/bash
echo "hello world from test.sh" >> itchanged.txt
所以,如果我更改Journal.txt,我应该得到一个名为itchanged.txt的文件。当我执行以下操作时:
$ launchctl unload ~/Library/LaunchAgents/com.me.helloworld.plist
$ launchctl load ~/Library/LaunchAgents/com.me.helloworld.plist
$ touch Journal.txt
运行ls命令会显示test.txt文件未创建。但是,如果我手动运行./test.sh,则会创建itchanged.txt文件。因此,问题似乎在于识别Journal.txt已更改并在发生更改时执行脚本的某个位置。
我正在使用OS X Mountain Lion操作系统。有任何想法吗?