Automate offlineimap sync using Launchd on Mac OSX

I am now on a mutt + offlineimap setup for both my work and personal emails (love thy mutt), I will put a post later on why and how am I doing it, posting how to automatically run the offlineimap on a MacOSX (10.8) using Launchd.

Create a file in user’s LaunchAgents directory, the label naming convention that Apple uses a typically weird but okay as long as it works:

~/Library/LaunchAgents/org.abhinav.mail.abhinav.plist

My offlineimap plist file looks like this:

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


        Label
                org.abhinav.mail.abhinav
        ProgramArguments
        
                /usr/local/bin/offlineimap
                -a AbhinavAbhinavOrg
        
        RunAtLoad
                
        StartInterval
                60
        TimeOut
                180
        StandardErrorPath
                /Users/abhinav/log/offlineimap_abhinav_error.log
        StandardOutPath
                /Users/abhinav/log/offlineimap_abhinav.log


Then run following to submit it to Launchd.

launchctl load ~/Library/LaunchAgents/org.abhinav.mail.abhinav.plist

In short, above plist file tells Launchd to start the offlineimap application with -a mailboxname argument every 60 minutes and start at load also, time it out if it’s running or stuck for more than 180 seconds and puts stdin and stderr in defined logs. Works beautifully for me.

I took help from here, here and Steve Losh’s guide to a homely mutt.

Subscribe
Notify of

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Dominique
8 years ago

Thanks for this post. I have a similar setup but the launchd job doesn’t seem to survive when the computer goes to sleep. I tried to add

KeepAlive

NetworkState


but that didn’t seem to help. I’m on 10.9. Any ideas?

Dominique
8 years ago

Wow. That markup didn’t quite work. I meant to type:

KeepAlive

NetworkState