Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have several instances of Firefox with several different profiles running. Among them profiles with the names "software" and "test".

I am trying to open an URL from a bash script to have it open in profile "test", like this:

firefox -P "test" http://www.example.org/

However that opens it in profile "software" anyway. Any ideas?

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100308 Iceweasel/3.5.8 (like Firefox/3.5.8)

No, it is not a permissions problem, all my profile directories are perfectly under my permissions:

root@przehyba:~/.mozilla# ls -ld firefox/
drwx------ 13 miernik miernik 4096 Mar 11 09:15 firefox/
root@przehyba:~/.mozilla# ls -ld firefox/*
drwxr-xr-x  9 miernik miernik 4096 Mar 12 11:29 firefox/info
-rw-r--r--  1 miernik miernik  560 Mar 11 09:15 firefox/profiles.ini
drwxr-xr-x 10 miernik miernik 4096 Mar 16 11:51 firefox/software
drwxr-xr-x  9 miernik miernik 4096 Mar 11 09:14 firefox/tech
drwxr-xr-x 11 miernik miernik 4096 Mar 15 22:48 firefox/test
root@przehyba:~/.mozilla# 
share|improve this question

7 Answers 7

If you already have an instance running, Firefox will reuse that. Try firefox -no-remote.

share|improve this answer
    
But I want it to reuse an instance! Only a specific one, not any random one it likes. If I tried adding "-no-remote" to my command, I get: "Iceweasel is already running, but is not responding. To open a new window, you must first close the existing Iceweasel process, or restart your system." –  miernik Mar 12 '10 at 7:48
    
Ah, that makes it more interesting. I am afraid I do not know how you could do that. IIUC, -no-remote disables "talking" between instances. This may be way off target and total overkill, but you could create an extension that polls a central file or server URL queue and opens it when it is meant for the current profile. You then install that extension in all of your instances. –  janmoesen Mar 12 '10 at 7:54

@miemik

"But I want it to reuse an instance! Only a specific one, not any random one it likes. If I tried adding "-no-remote" to my command, I get: "Iceweasel is already running, but is not responding. To open a new window, you must first close the existing Iceweasel process, or restart your system."

You have a permission problem with your profile dir...check the permission. Did you copy or move it from anyother place(partition..disk..)?

Solution:

Become root and run top to see if it's running as root. Then ls -ld on the profile dir(whichh should be under ur home dir with a period(.) in front of them..means you have to use "ls -al" to see it.

Verify other permission of that dir and change accordingly.

Cheers!

share|improve this answer
    
I checked the permissions and pasted the result in an edit to my question. It is not that problem. –  miernik Mar 16 '10 at 10:56

It won't work. The only way to have 2 instances of a Mozilla app running is by disabling remote connections to the second one (usually with MOZ_NO_REMOTE=1). That means you disable the ability for it to communicate with other instances (like one creating opening a new page).

So your choices are either to open a new app with no remote enabled, or to reuse the instance that allows remote access.

share|improve this answer
    
It indeed works, see errge's answer. What do you mean by it won't work? –  pts Jan 17 at 12:47

You should be able to add the -no-remote to only the test profile call (after the software profile is already open) like this:

firefox -P "test" -no-remote http://www.example.org/

That should allow all other links to still open in your other profile remotely.

If this solution does not work you could always run Firefox as a separate user for testing, using sudo -u. Firefox really should be able to handle this properly with profiles though.

share|improve this answer
    
This answer can't be good because with the -no-remote flag a new Firefox instance is started, and the question requires reusing the existing Firefox instances if they are already running. –  pts Jan 17 at 12:46

For the record, one solution is: in KDE we set the default browser to run with the following command:

firefox -P "default"

where "default" is our profile we want to use each time.

Now, we start our Firefox instance with no arguments (the default KDE Firefox launcher). This opens Firefox normally, now we want to open another profile, to do so, we make another launcher in KDE menu editor:

firefox -ProfileManager -no-remote %u

This opens the profile manager, we choose which profile to use.

Tested on several profiles concurrently running, when we click on an url from any app (like a chat client), a new tab is then opened in the profile we've chosen.

Hope someone finds this helpful :).

Not tested on Gnome, but I hope it could be replicated.

share|improve this answer
1  
This does not answer the question, the OP wants to launch firefox with different profiles from a script automatically. –  terdon Oct 11 '12 at 23:54

If you have Mozilla Firefox already open with the Default profile or anyother profile, try:

Path-To/firefox -remote openurl("http://www.example.org")

Tested and worked for me with Mozilla Firefox from 2.x to 12.x

share|improve this answer
    
This answer can't be good because the command-line doesn't contain the required profile to use. –  pts Jan 17 at 12:45

Sorry for the 3 years late answer, I became interested in this topic just now and found this question.

I didn't find a documented solution anywhere, so I checked out the source code and here is a very relevant part: http://dxr.mozilla.org/mozilla-central/source/toolkit/xre/nsAppRunner.cpp#1537

Here, the nullptr at the end of the line unfortunately means that the profile argument is not being passed to the SendCommandLine function, therefore it's not possible to select the correct firefox window to send the openurl message to.

However, we see that the username is being passed and that the username is being intiailized from the LOGNAME environment variable. Based on this, I came up with the following solution:

  • I wrap firefox with this script, called firefox.sh:
FOX_PROFILE=facebook
export LOGNAME=errge.$FOX_PROFILE
/opt/firefox/firefox -profile ~/.mozilla_profiles/$FOX_PROFILES "$@"
  • when ran the first time, it starts a new instance and the ~/.mozilla_profiles/facebook directory has to exist,

  • when ran the second time if the facebook profile is already running, it correctly connects to it,

  • it can send commands correctly to multiple different running profiles (of course you have to change the FOX_PROFILE parameter in the first line in the different scripts).

I tested this with Firefox 26 on Linux and it works.

Alternatively, here is my full-fledged solution that you may want or not want to use:

#!/bin/bash

set -e

FOX=/opt/firefox/firefox

MESSAGE=$@

if [ -z "$FOX_PROFILE" ]; then
  if [ -z "${MESSAGE}" ]; then
    FOX_PROFILE=default
  else
    FOX_PROFILE=$(kdialog --default default --menu "-- ${MESSAGE} --" default default google google facebook facebook errge errge spam spam)
  fi
fi
export FOX_PROFILE

# This hack is needed, because firefox remote command line sending
# ignores the profile parameter.  See nsAppRunner.cpp:1505.
export LOGNAME=errge.$FOX_PROFILE

# Using background execution instead of exec, so the behavior is
# consistent when the profile is already running and when it's just
# starting up.
$FOX -profile ~/.mozilla_profiles/$FOX_PROFILE "$@"

# Huge success.
exit 0

If you run the script without any parameter, it autoselects the default profile, but you can override it by setting FOX_PROFILE by hand in your shell. If an URL is passed in the command line, it always asks for a profile in which to open it, this is because I mainly click through from my chat and email program and in those case I want to always select a profile (google for calendar spam, facebook for birthday spam, etc.). Of course you can change the logic to fit your style of usage, this is just an example, the important knowledge is the LOGNAME trick.

And of course you have to make sure that this wrapper script is the only way to start the browser on your machine. Because if you open a profile without the correct LOGNAME set, than you won't be able to communicate to that profile anymore. I put this script as first in my path via multiple symlinked names, like x-www-browser, firefox, sensible-browser and put it in the BROWSER environment variable too. How to do this exactly depends on your GNU/Linux distribution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.