Wednesday, October 28, 2009

Sync Firefox profiles across computers with Dropbox

Dropbox is a fantastic service that will sync data between multiple computers and keep it backed up on their server. Since I use multiple computers on an almost daily basis I love Dropbox because I can work on the same files on either computer and they remain synced. I recently started working on a a project involving Mozilla Firefox. I wanted to created a second Firefox profile to keep my project preferences, add-ons, and history separate from my regular profile while at the same time being synced between my laptop and desktop.

I started on my desktop, which runs Ubuntu Linux. In order to create a new Firefox profile without damaging the current one you have to start the Firefox Profile Manager:
$ /usr/bin/firefox --profilemanager
If you are working on a Mac you can start it like this:
$ open -a firefox --args --profilemanager
If you are working in Windows you can start it like this:
c:\>"Program Files"\"Mozilla Firefox"\firefox.exe --profilemanager
The Profile Manager is a GUI tool so once you create a new profile, I called mine "dev", just click the exit button. Firefox will still start with the default profile. In order to use the new profile you need to throw an argument to the Firefox binary to tell it which profile you want to use. In Linux, to load up a new instance of Firefox using your new profile called "dev", even if one is already running, run this command:
$ /usr/bin/firefox -no-remote -P dev
Doing this, however, will keep that instance of Firefox tied to your terminal. To get around this I created a new launcher that sits on my panel at the top of my screen. To do that, right-click the panel, choose "Add to Panel...", then "Custom Application Launcher". Fill out the box that comes up so it looks like this:

On a Mac, to open Firefox with a new profile its easiest to run this command from the Terminal:
$ open -a firefox --args -no-remote -P dev
On Windows it would look like this:
c:\>"Program Files"\"Mozilla Firefox"\firefox.exe -no-remote -P dev
In Windows you can also create a shortcut to firefox and add the arguments at the end of the path in the properties window so it looks like this:

The way I got syncing to work uses symbolic links. I've written about Unix symbolic links before and they rock. After I made sure the new Firefox profile worked on my Linux desktop shutdown all instances of Firefox. In Linux, your Firefox profiles reside in this folder:
Each profile has a unique name which follows a pattern of 8 seemingly random alphanumeric characters, followed by a period (.), followed by the name of the profile. If you have two Firefox profiles whose names are "default" and "dev" their names might look like this, respectively: "5e97feg7.default" and "". To continue with those examples, I moved the "dev" profile to my Dropbox folder, located at ~/Dropbox/:
$ mv ~/.mozilla/firefox/ ~/Dropbox/
Then I created a symbolic link from the new location going back to the old one:
$ ln -s ~/Dropbox/ ~/.mozilla/firefox/
Now, if you did everything correctly, you should be able to open Firefox using your new profile, the one you just moved, and it should work like before. Next I moved to my Mac to get everything setup there. I created a symbolic link from the profile in my Dropbox directory into the directory where Firefox profiles live, located here:
~/Library/Application Support/Firefox/Profiles/
To create the new symbolic link:
$ ln -s ~/Dropbox/ ~/Library/Application Support/Firefox/Profiles/
Now you need to edit the config file that tells Firefox about the new profile, located here:
~/Library/Application Support/Firefox/Profiles/profiles.ini
Start by closing all instances of Firefox. Then, make a backup copy of the original:
$ cp ~/Library/Application\ Support/Firefox/Profiles/profiles.ini ~/Library/Application\ Support/Firefox/Profiles/profiles.ini.orig
You need to modify that profiles.ini file so it looks like this:



Now you should have a working Firefox profile that syncs between two different computers. I wouldn't recommend trying to run both at the same time though, as you are likely to fun into locked file issues and develop conflicting versions of files.

There was one other issue I had to deal with; one of the Firefox add-ons I am working with is Greasemonkey. When you edit your Greasemonkey scripts, the first time you are asked to pick out the text editor you want to use. Well on my Mac I use Smultron and in Linux I use gedit. Each time I would switch operating systems I would again be asked which text editor I wanted to use. In OS X, the path to Smultron is /Applications/ So on my Linux machine I created a directory called /Applications and put inside it a hard link to gedit that I renamed. I did it like this:
$ sudo mkdir /Applications
$ sudo ln /usr/bin/gedit /Applications/
Now no matter which operating system I use, Greasemonkey looks for /Applications/ when I want to edit scripts.

1 comment:

  1. Hi, I just did the same thing but between Mac and Windows. Do you have any idea how make the Greasemonkey editor to be recognized between both systems?