Syncing iPad/iCloud and Dropbox

In case anyone else is wanting to sync a vault on iPad with Dropbox/macos, this is the approach I’ve come up with. It uses Unison for file syncing, so you’d need to install this first, but that’s easy with e.g. homebrew.

Then:

  • Make a new clean vault on the iPad
  • Wait for it to sync with the macbook - it’ll show up eventually in ~Library/Mobile Documents/iCloud~md~obsidian/Documents/<vault_name>
  • Delete the .obsidian directory in there, then copy everything from the Dropbox vault in (including .obsidian)
  • Use unison to sync the two, e.g. unison ~/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/<vaultname> ~/Dropbox/<path_to_vault>

It will normally complain a bit the first time, but should run smoothly on subsequent syncs.

To make it easier, you can add a preference to unison for these vaults. In ~/Library/Application Support/Unison, make a file called obsidian.prf, with the full path to the directories in, i.e.

# Roots of the synchronization
root = /Users/<yourname>/Library/Mobile Documents/iCloud~md~obsidian/Documents/<vaultname>
root = /Users/<yourname>/Dropbox/Obsidian/<vaultname>

Then, you can run unison -batch obsidian, and it will sync the two vaults.

If that works, then you can add a script (on the macbook) that will sync after any file changes. From the instructions here, I created the following - replace the bits in {curlies} with your own info:

<?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>{some.id.you.make.up}</string>
        <key>ProgramArguments</key>
        <array>
                <string>/opt/homebrew/bin/unison</string>
		<string>-batch</string>
		<string>obsidian</string>
        </array>
        <key>WatchPaths</key>
        <array>
                <string>/Users/{username}/Library/Mobile Documents/iCloud~md~obsidian/Documents/Main</string>
                <string>/Users/{username}/Dropbox/Obsidian/Main</string>
        </array>
	<key>ThrottleInterval</key>
	<integer>30</integer>
</dict>
</plist>

Put it in ~/Library/LaunchAgents with a sensible name, and then run launctl load <your file.plist> to add it to the list of daemons and load it at startup.