我写了一个代理来监控关键系统文件:ag1-launchagents
#!/bin/bash
arg1=/System/Library/LaunchAgents
fswatch $arg1 "growlnotify -n "FSWatch" -m "FSWATCH:Changed:$arg1" -s"
我为其他 6 个目录创建了相同的文件,以分别监控它们的更改并通过 growlnotify 打印通知。使用命令行,脚本工作得非常好。
下一步是通过 *.plist 文件自动启动 ag1-ag7:
<?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.user.fswatch</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/Shell/ag1-launchagent.sh</string>
<string>/Library/Scripts/Shell/ag2-launchdaemons.sh</string>
<string>/Library/Scripts/Shell/ag3-bin.sh</string>
<string>/Library/Scripts/Shell/ag4-etc.sh</string>
<string>/Library/Scripts/Shell/ag5-usrbin.sh</string>
<string>/Library/Scripts/Shell/ag6-usrsbin.sh</string>
<string>/Library/Scripts/Shell/ag7-sbin.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>Nice</key>
<integer>10</integer>
<key>KeepAlive</key>
<false/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
但它不起作用。
plist 似乎是正确的。我通过plutil检查了它。但是,每当我通过 launchctl load *.plist 运行 plist 并更改代理应观察的任何文件夹时,我都没有收到任何通知。
注意:我在 ProgramArguments 块中用一行进行了尝试,只启动了一个 *.sh 文件。但它也没有奏效。
对此有什么想法吗?