Opening Multiple Instances of Safari or Firefox on Mac OS X


Couple of weeks ago, a friend of mine, who mainly uses Linux operating system, complained that when he tries to open a new window of Safari in different desktop, the operating system automatically switches back to the desktop (spaces) that the safari is running.

In Linux, as in MAC, you can have multiple virtual desktops. This helps to organize the programs that are running simultaneously. Particularly, once you have many windows and application running at the same time. However, in Linux once you click on Firefox icon, the Firefox will start working in that desktop.

However, this is not the case on MAC OS X. Once you click on the Safari or Firefox icon, it takes you back to the original desktop where you started this application for the first time. This also happens when you use Command+N to open a new window.

Well, one quick work around is to open the new window and then move it to your desired desktop. But I do agree this is not solving the problem but rather more of erasing the problem or changing the question.

Well, then let’s solve the problem for real.

In linux, once you click on the Firefox icon, the operating system starts a new instance of that software, with completely different Process ID (PID). However, in MAC it does not do that. Even when you are opening a new window, that new window is still running under the same PID. You can check the PID using /Applications/Utilities/Activity Monitor.

So, all we need to do is to force the MAC to start a new instance. But how?

If you are using the command prompt (Terminal), you can do this by typing:

open -n /Applications/Safari.app

You can execute this command as many times as you want. Each time a new instance of Safari with totally different PID is going to run. But remember, you also get multiple icon of Safari on the Dock, as you get multiple tab on windows or Linux. So, if you have 10 instances of Safari, there are going to be 10 Safari icon on the Dock. Exactly as in windows and Linux. This may justify why MAC is not running multiple instances of the same application by default.

If you want to have multiple instances of Firefox, or any other application, you just need to provide the path to that application in the above command.

One way to make this easier, is to make an alias for each command, such as:

alias NewSafari=’open -n /Applications/Safari.app’

This is easier. Now you just need to type NewSafari in the command prompt and you get your new instance of Safari. You can also put this line in your ~/.profile; so every time that you fire up the terminal, this command is available.

But still this is not the solution. Since, this requires first running the terminal and then running a command. What we are looking here is an icon on the dock, which once clicked opens a new instance of the Safari, or any other application of your choice.

Here what you should do:

Step 1: Open AppleScript Editor. Just type AppleScript in spotlight and then enter.

Step 2: After the AppleScript editor opened, type the following command in it.

do shell script "open -n /Applications/Safari.app"

NOTE: if you are copy/pasting the above script, make sure to retype the double quotes, i.e. “. WordPress uses a different character code, which looks nicer; however, it is not recognizable by apple script. So, either type the entire command, or if you copy/paste retype the double quotes again.

Step 3: Now chose File -> ‘Save Aa’, choose a name, for example Safari, and make sure that “Application” is selected in “File Format”.

I have a folder called ~/myscripts where I store all the scripts that I write. You may also want to have a folder to store your scripts.

Practically you are done. By clicking on this application that you just created a new instance of Safari is opened every time that you click it. You can drag it to the dock so you can access it even faster.

However, the icon does not look like Safari icon yet. If you want to change the icon of this new application that you just wrote, follow these easy step.

Step 1: Right click on /Applications/Safari and choose “Get Info”. Then in the Get Info window click on the Safari Icon. Once the icon started to glow, press command+c.

Step 2: Now right click on the application that you wrote, eg. ~/myscripts/Safari.app, and choose “Get Info”. Click on the icon on top. Once it starts to glow, press command+v.

That was it. You changed the icon. Now you can put this on the dock and whenever you want to start a new instance of safari, just click on this icon.

NOTE: for the workaround for Firefox go to here.

Hope this was helpful.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

19 Responses to Opening Multiple Instances of Safari or Firefox on Mac OS X

  1. Joann Phan says:

    THis is exactly what I am looking for, however, when I typed in “open -n /Applications/Safari.app” on AppleScript, saved it under ‘application’, and renamed it to Safari… it gave me this error message:
    ‘ Syntax error A unknown token can’t go after this identifier.’
    It also highlighted the word Safari on AppleScript

    • mabouali says:

      In AppleScript, you must type:

      do shell script “open -n /Applications/Safari.app”

      and save it as application. Don’t forget the

        do shell script

      part above.

      Hope this will solve your issue.

    • mabouali says:

      Oh, by the way, If you are copy/pasting the script line from wordpress retype the double quotes again, i.e. after pasting the line, delete the double quotes and retype them again. WordPress uses different characters for double quotes which look much nicer, but not recognizable by AppleScript.

    • Mike says:

      i tried this but get the same problem with it opening a new window in the original safari space. i’m using version 10.5.8 if that makes a difference. is there anything else that you can think of that i could try? your instructions were very easy to follow.

      • mabouali says:

        As I have mentioned, do not copy paste from the blog. If you do, make sure that you correct the double quotes. WordPress uses different character for opening and closing double quotes. So, just retype them again.

  2. Chris says:

    I copied and pasted the script in the Apple Script editor and got the same error message when attempting to save. I know how to write DOS batch scripts, but am a newbie with the Apple Scripts.

    • mabouali says:

      Hi,
      thanks for your interest in this post.
      When you copy/paste the script from the website, you need to delete the double quotes and retype them again. WordPress uses a different character code for double quotes i.e. (“), which looks much nicer; however it is not recognizable by apple script. Therefore, just go over the script again and delete the double quotes and retype them again. Then you shouldn’t get the error.

      Hope this will solve the problem.

  3. jsherk says:

    Hi
    Was hoping this would work with FIrefox on Lion (10.7.3) but typing in Terminal:
    open -n /Applications/Firefox.app
    brings up popup that says
    “A copy of Firefox is already open. Only one copy of Firefox can be open at a time.”
    From the dock, you can select firefox icon and choose New and it will open new Firefox window but cannot figure out how to do it from command line.
    Thanks

  4. jsherk says:

    To answer my own question above about it not working with Firefox, I found this:
    http://superuser.com/questions/396434/os-x-lion-and-firefox-how-to-open-new-window-with-terminal

    • mabouali says:

      Thanks for sharing your findings here. I really Appreciate it.

      The link you mentioned only shows how to open a new window of Firefox, which would be under the same PID. So, they are not multiple instances of firefox. As an example if you quit one of the window all of them will quit.

      Anyway, check my new post on how to open a truly new instance of firefox.

      cheers,

      P.S. thanks for posting your findings though. Keep sharing. I appreciate it.

      regards

  5. Pingback: Opening Multiple Instances of Firefox | Welcome to the website of Mohammad Abouali

  6. mareoraft says:

    The following is slightly simpler. Let’s say I wanted to open the application Preview.

    Open Terminal, type the command

    open -na Preview

    Explanation: The -n option is for “new” or “new instance”. The -a option tells your computer you are opening an application, so that the path (usually /Applications/) and the extensions (.app) are no longer needed.

  7. Nickp says:

    dare you to try

    repeat
    do shell script “open -na safari”
    end repeat

  8. Pingback: Firefox: Open multiple instances - Faux Pleather

  9. Pingback: How to Run Multiple Instances of the Same App in Mac OS X - Science & Tech | Tech wikiHow

  10. Chris says:

    Thanks mabouali,

    Your instructions above for opening a second instance of Safari from the dock worked perfectly. Of course when I click on my new icon, it opens another (i.e. a 3rd), ‘normal’ Safari icon in the dock, but maybe there is no way around that. (I’m on OSX 10.9) However it seems that the first and second instances of Safari are linked in that cookies are shared in the same space. When a site is visited in one Safari browser, cookies for it appear in the other (viewed using Safari Cookies). My question is this; is it possible to keep the two instances of Safari separate so that they don’t share cookies of any kind? Could, for example, Gmail and other google services be confined to one instance where they can’t ‘see’ what the other instance is doing? Or is the only way to do this to use a different browser (e.g. Firefox)?

    • mabouali says:

      I proposed that method when I was using 10.7 (I guess). I have not personally test it on 10.9

      The goal of it was exactly for gmail account that you can log in on multiple account. Based on your response, I guess it is no more working on 10.9.

      • Chris says:

        The two different instances of Safari do allow two different, simultaneous logins with gmail, so this still works. However, somehow it works despite my point above, that the cookies seem to be stored in a shared place.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s