Monday, July 02, 2012

Sync Sublime Between Multiple Macs

I’ve been using Sublime Text 2 since way, way back when it was just starting to be developed. I’ve used it since and still love it. It’s light, fast and extensible. However, something that I wanted was the ability to have it in sync between my two Macs. I know, first world problem, but something I wanted a solution to nonetheless. I have an iMac at home and a MacBook Air that I use at the office, when I’m not working remotely from my home office. Using Dropbox I was able to easily accomplish this. Please note that this is for Mac OS X, and should also work on Linux, but probably not on Windows (possible solution here)

Install Sublime Text 2

This should be obvious, but if you haven’t installed Sublime Text 2 already, you’ll want to do this first. You can grab your copy here and I’d encourage you to purchase a license to support the developer.

Install Dropbox

I’m using Dropbox to keep my settings, packages and other supporting files in sync between my two Macs. Now I’m sure you have Dropbox already, but if you’re the 1 person left on the planet that doesn’t, then please use this link so that both you and I receive an extra 500MB free for our accounts.

You’ll want to make sure you have Dropbox installed on all of the Mac’s you’ll want to have your settings in sync.

Setup Sync on First System

Here are the steps I took to setup the sync. I did this on my iMac desktop first, then my MacBook Air second (shouldn’t matter which one you do first, just one at a time). Note that this requires you to use the Mac OS X Terminal, or the excellent iTerm2.

  1. Quit Sublime Text 2 if it’s running
  2. Open the Terminal or iTerm2
  3. Change to your Dropbox folder
    cd ~/Dropbox
    
  4. I recommend creating a new folder for Sublime Text 2 to organize everything. I created one for the Application Support folder and one for the Preferences file. This is what I did, but you can use a different path if you want:
    mkdir -p ~/Dropbox/Applications/Sublime\ Text\ 2/Application\ Support
    mkdir -p ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences
    
  5. Now we move your current Preferences file to the new Dropbox folder
    mv ~/Library/Preferences/com.sublimetext.2.plist ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/
    mv ~/Library/Preferences/com.sublimetext.2.plist.lockfile ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/
    
  6. Now we need to create a symlink for each of those files. The symlink will be in the ~/Library/Preferences folder where Sublime Text 2 looks for the Preferences file, and will point to the actual copy that’s stored in your Dropbox folder
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/com.sublimetext.2.plist ~/Library/Preferences/com.sublimetext.2.plist
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/com.sublimetext.2.plist.lockfile ~/Library/Preferences/com.sublimetext.2.plist.lockfile
    
  7. As you probably guessed, we need to do the same thing with the Application Support folder, move it then symlink it.
    mv ~/Library/Application\ Support/Sublime\ Text\ 2 ~/Dropbox/Applications/Sublime\ Text\ 2/Application\ Support/
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Application\ Support/Sublime\ Text\ 2 ~/Library/Application\ Support/Sublime\ Text\ 2
    

At this point your first computer should be setup to use the Preferences file and Application Support folder (contains your packages, key-bindings, etc) stored in your Dropbox. Go ahead and launch Sublime Text 2, it should open just like before, nothing should be different.

Setup Sync on Second System

Now go to your second system. Install Dropbox if you haven’t already, At this point it’s important to wait for Dropbox to finish it’s sync. If you haven’t already installed Sublime Text 2, go ahead and do that as well, but don’t launch it.

Now let’s setup this second computer to point to the Dropbox versions of the Preference file and Application Support folder.

  1. Quit Sublime Text 2 if it’s running
  2. Open the Terminal or iTerm2
  3. Change to your Dropbox folder
    cd ~/Dropbox
    
  4. If you’ve run Sublime Text 2 on this second computer before, we’ll rename the current Preference file and Application Support folder so that these are saved, but not used. If you’ve never run Sublime Text 2 on this second computer, skip to the numbered step
    mv ~/Library/Preferences/com.sublimetext.2.plist ~/Library/Preferences/old-com.sublimetext.2.plist
    mv ~/Library/Preferences/com.sublimetext.2.plist.lockfile ~/Library/Preferences/old-com.sublimetext.2.plist.lockfile
    mv ~/Library/Application\ Support/Sublime\ Text\ 2 ~/Library/Application\ Support/Old\ Sublime\ Text\ 2
    
  5. Now let’s setup the symlink for the Preference file
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/com.sublimetext.2.plist ~/Library/Preferences/com.sublimetext.2.plist
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Preferences/com.sublimetext.2.plist.lockfile ~/Library/Preferences/com.sublimetext.2.plist.lockfile
    
  6. Then the Application Support folder
    ln -s ~/Dropbox/Applications/Sublime\ Text\ 2/Application\ Support/Sublime\ Text\ 2 ~/Library/Application\ Support/Sublime\ Text\ 2
    

At this point you should be able to launch Sublime Text 2 on the second computer and have all of your same Preferences, packages and key-bindings setup and installed. Note that I haven’t run Sublime Text 2 on both computers at the same time, so I can’t comment on what this may or may not do.

3 comments:

Unknown said...

I'm using this method for many apps.
I have move some folders in Application Supports, then I've do this

# App pref sync
cd ~/Library/Application\ Support/; ls -1 ~/Dropbox/Library/Application\ Support/ | sed 's/\ /\\\ /g' | xargs rm -rf
ln -s ~/Dropbox/Library/Application\ Support/* ~/Library/Application\ Support
rm -rf ~/Library/Preferences
ln -s ~/Dropbox/Library/Preferences/ ~/Library/Preferences
rm -rf ~/Library/Fonts
ln -s ~/Dropbox/Library/Fonts ~/Library/Fonts
rm -rf ~/Library/StickiesDatabase
ln -s ~/Dropbox/Library/StickiesDatabase ~/Library/StickiesDatabase

There is still some issues sometimes (dock or some conflicts) but it works great in general.

Troy said...

Interesting idea of moving all of your Preferences and Fonts over. Does that work for the new sandboxed applications as well that are stored in ~/Library/Containers

Wade Hammes said...

Tested with both instances running at the same time, any pref change is simultaneous. It is pretty awesome. About a 1s delay on second machine. I tested with Zoom level.