我並不是很精通所有事情launchd
,但我編寫了這個plist
文件,該文件定期運行offlineimap
以從 IMAP 伺服器獲取新郵件:
<?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>net.dpo.offlineimap</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/offlineimap</string>
<string>-o</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ProcessType</key>
<string>Background</string>
<key>StartInterval</key>
<integer>1800</integer>
</dict>
</plist>
該文件位於~/Library/LaunchAgents/net.dpo.offlineimap.plist
.
問題是當我將電腦從睡眠狀態喚醒時,該進程似乎沒有喚醒。跑步
$ launchctl stop net.dpo.offlineimap
$ launchctl start net.dpo.offlineimap
重新激活它,但這似乎破壞了該KeepAlive
選項。
我嘗試使用
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<true/>
<key>NetworkState</key>
<true/>
</dict>
但我觀察到同樣的行為。我使用的是 OSX 10.9。我的~/.offlineimaprc
沒有使用該autorefresh
選項。
文件有什麼問題嗎plist
?
先致謝!
答案1
嗯,我可能誤會了 的意思KeepAlive
。事實證明自製分發一個plist
文件來offlineimap
完成這項工作:
<?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>KeepAlive</key>
<false/>
<key>Label</key>
<string>homebrew.mxcl.offline-imap</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/offline-imap/bin/offlineimap</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>RunAtLoad</key>
<true />
<key>StandardErrorPath</key>
<string>/dev/null</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
</dict>
</plist>
該守護進程現在可以在睡眠中存活。