Syncing Things with git and Launchd

For the more geeky amongst you here's a way to keep an automatic sync using git and launchd.

First set up your repo

cd Library/Application\ Support/Cultured\ Code/Things
git init
git add .
git commit -a -m "initial commit"

Then set up a remote repo (you must have an ssh key installed so you can push and pull updates without a password).

ssh host.com
mkdir things.git
cd things.git
git --bare init

Now, back in your local directory

git remote add origin host.com:things.git
git push origin master

Okay! Now you've got a git repository set up.

Now put this code into a file called thingssync.sh

#!/bin/bash
DATE=`date`
cd ~/Library/Application\ Support/Cultured\ Code/Things
git pull origin master
git commit -a -m "Auto Sync - $DATE"
git push origin master

make it executable

chmod +x thingssync.sh

and put it in your /usr/bin

sudo cp thingssync.sh /usr/bin/

Now copy this file into a plist called com.example-host.ThingsSync.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">

<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.twelvestone.ThingsSync</string>
    <key>Program</key>
    <string>/usr/bin/thingssync.sh</string>
    <key>RunAtLoad</key>
    <true />
    <key>StartInterval</key>
    <integer>1800</integer>
  </dict>
</plist>

Then put it in your ~/Library/LaunchAgents directory (you might have to create the directory first)

mkdir -p ~/Library/LaunchAgents
cp com.example-host.ThingsSync.plist ~/LaunchAgents

Now load it into launchd

launchctl load ~/Library/LaunchAgents/com.example-host.ThingsSync.plist

And your Things data will be synced every half hour when your computer is awake.