Open Firefox with a clean profile

Aug 18, '09 07:30:49AM

Contributed by: CaptnEvilStomper

I just finished writing an AppleScript that will let you run Firefox with a clean profile. If Firefox isn't already running when you run this script, it'll open Firefox normally, but load a clean profile instead of the default one. If Firefox is running, the script will open a new instance of Firefox alongside the current one and load the clean profile in that. If you already have both your default profile and the clean profile open, it'll just bring the clean one into focus.

Before we get to the actual script, you'll need to open Firefox's profile manager and create a new profile. Open a new Terminal window and type this:

/Applications/Firefox.app/Contents/MacOS/firefox -profilemanager
...then hit Return. This assumes that Firefox is in the Applications folder; if you have it somewhere else, change the path to wherever you put it. When the Profile Manager opens, click Create Profile, and name it whatever you want (I used "Clean"). If your profile name is longer than one word, make sure you use underscores or dashes instead of spaces. Once you're done, click Exit. Now for the script. Copy and paste this into Script Editor:

on run
   set ffPath to "/Applications/"
   set ffName to "Firefox"
   set ffProfile to "clean"

   set findFF to "ps -ef | grep firefox | grep -v grep | grep -v sh | awk '{print$2}'"
   set pinfo to do shell script findFF
   set oldPnum to count words of pinfo
   if oldPnum is less than 2 then
       do shell script ffPath & ffName & ".app/Contents/MacOS/firefox -P " & ffProfile & " &> /dev/null &"
   end if
   set newPnum to oldPnum
   repeat while newPnum = oldPnum
       delay 0.25
       set pinfo to do shell script findFF
       set newPnum to count words of pinfo
   end repeat
   if newPnum is less than 2 then
       set ffPID to word 1 of pinfo as integer
   else
       set ffPID to word 2 of pinfo as integer
   end if
   tell application "System Events" to set frontmost of every process whose unix id is ffPID to true
end run
This script assumes that Firefox is in the Applications folder, that it's named "Firefox", and that the profile is named "clean". If not, then change those variables at the top of the script to match your setup. You can also tell Firefox to load a specific URL when it opens, by adding a space and then the website after the profile name. For example, changing "clean" in the script to "clean http://google.com" will load the clean profile and take you to the Google home page. Once everything's in order click File: Save as, make sure that Startup Screen is unchecked, and save it as an Application Bundle.

[editor adds: I have not tested this hint.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2009081403234968