1

I'm not very well versed in all things launchd but I wrote this plist file that periodically runs offlineimap to fetch new mail from IMAP servers:

<?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>

The file is located in ~/Library/LaunchAgents/net.dpo.offlineimap.plist.

The issue is that the process doesn't seem to wake up when I wake the computer from sleep. Running

$ launchctl stop net.dpo.offlineimap
$ launchctl start net.dpo.offlineimap

reactivates it, but that seems to defeat the KeepAlive option.

I tried using

<key>KeepAlive</key>
  <dict>
    <key>SuccessfulExit</key>
      <true/>
    <key>NetworkState</key>
      <true/>
  </dict>

but I observe the same behavior. I'm on OSX 10.9. My ~/.offlineimaprc doesn't use the autorefresh option.

Is anything wrong with the plist file?

Thanks in advance!

0

Well, I may be misunderstanding the meaning of KeepAlive. It turns out Homebrew distributed a plist file with offlineimap that does the job:

<?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>

The daemon now survives sleep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.