我开始使用launchd并且想要设置一个plist文件,这样每当我将SD卡插入我的Mac mini服务器(使用Snow Leopard Server)时,我想要一个shell脚本运行(应该复制所有的jpg文件) ,重命名他们等).
所以,我在〜/ Library/LaunchAgents中创建了一个plist文件(请参阅下面的内容 - 它应该寻找/ Volumes的更改)并创建了一个shell脚本,上面写着"beep" - 稍后它会做一些更有用的事情.
plist文件与launchctl注册,当我运行它(launchctl开始com.peters.runwhenSDmount),电脑说,每当一个存储卡已插入哔声,在没有存储卡的保持沉默.因此,plist确实调用了shell脚本,随后检查特定的SD卡是否存在.我认为这也证明了SD卡的权限没有问题.
但是,它似乎并不自行运行??? 知道为什么??
plist文件:〜/ Library/LaunchAgents/com.peters.runwhenSDmount.plist
<?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">
<dict>
<key>Label</key>
<string>com.peters.runwhenSDmount</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Users/peter/Library/Scripts/runwhenSDmount</string>
</array>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
shell脚本:〜/ Library/Scripts/runwhenSDmount
#!/bin/bash
if [ -d "/Volumes/NIKON D40X" ]; then
say beep
fi
Run Code Online (Sandbox Code Playgroud) launchd ×1