Running multiple instances of Mozilla

Written by Michael Hipp on 18-June-2002.

By popular demand, here is how to get mozilla 1.0 to not complain when you try to run multiple instances. So I offer the following as a SxS under mozilla or mail or both.

Mozilla 1.0 was changed from rc2 such that profiles cannot be shared among multiple instances of the program. Mozilla locks the profile to prevent multiple instances from running. The answer is to just run multiple windows from the one instance. But there is no easy way to force this behavior from outside mozilla. An example is when clicking on a link in your favorite (non-mozilla) email program. Mozilla will refuse to bring up the link if it was already running.

So a change is needed to 'run-mozilla.sh' to cause it to invoke the '-remote openURL(%u,new-window)' behavior.

To do this apply the patch below to run-mozilla.sh.

As root, copy the patch file (named run-mozilla.patch) to /usr/lib/mozilla
(that's where run-mozilla.sh is on my Gentoo system):

cd /usr/lib/mozilla {or whereever}
patch < run-mozilla.patch

If it patches cleanly, open run-mozilla.sh in your favorite editor and search for the string "openurl". If it's there the patch was probably successful.

To test the patch, go to the cli and type 'mozilla' 3 times in a row and see if 3 instances come up without complaining. That's all we wanted. (Actually it is not 3 instances and all the resource wasting that would imply; it is 1 instance, 3 windows).

To make kmail use mozilla when you click on a link, go to
Kde Control Center -> File Browsing -> File Associations -> Text -> html
Add mozilla to the top of the 'Application Preference Order' and use the command 'mozilla %u' without the quotes.

Now when you click on a link in Kmail, mozilla should come up every time, no matter how many windows are already open or it will start up if none were open. What an idea!

Patch: run-mozilla.patch


Index: build/unix/run-mozilla.sh
===================================================================
RCS file: /cvsroot/mozilla/build/unix/run-mozilla.sh,v
retrieving revision 1.41
diff -u -r1.41 run-mozilla.sh
- --- build/unix/run-mozilla.sh 12 May 2002 21:25:04 -0000 1.41
+++ build/unix/run-mozilla.sh 6 Jun 2002 11:50:37 -0000
@@ -65,10 +65,11 @@
#
cmdname=`basename $0`
MOZ_DIST_BIN=`dirname $0`
- -MOZ_DEFAULT_NAME="./${cmdname}-bin"
- -MOZ_APPRUNNER_NAME="./mozilla-bin"
- -MOZ_VIEWER_NAME="./viewer"
+MOZ_DEFAULT_NAME="${MOZ_DIST_BIN}/${cmdname}-bin"
+MOZ_APPRUNNER_NAME="${MOZ_DIST_BIN}/mozilla-bin"
+MOZ_VIEWER_NAME="${MOZ_DIST_BIN}/viewer"
MOZ_PROGRAM=""
+MOZ_CLIENT_PROGRAM="${MOZ_DIST_BIN}/mozilla-xremote-client"

exitcode=0
#
@@ -131,6 +132,18 @@
return 0
}
##########################################################################
+function check_running() {
+ $MOZ_CLIENT_PROGRAM 'ping()' 2>/dev/null >/dev/null
+ RETURN_VAL=$?
+ if [ "$RETURN_VAL" -eq "2" ]; then
+ echo 0
+ return 0
+ else
+ echo 1
+ return 1
+ fi
+}
+##########################################################################
moz_get_debugger()
{
debuggers="ddd gdb dbx bdb"
@@ -438,9 +451,46 @@

if [ $moz_debug -eq 1 ]
then
- - moz_debug_program ${1+"$@"}
+ moz_debug_program ${1+"$@"}
else
- - moz_run_program ${1+"$@"}
+ USE_EXIST=1
+ ALREADY_RUNNING=`check_running`
+ if [ "${ALREADY_RUNNING}" -eq "1" ] && [ -n "$1" ]; then
+ USE_EXIST=0
+ opt="$1"
+ case "$opt" in
+ -mail)
+ exec $MOZ_CLIENT_PROGRAM 'xfeDoCommand(openInbox)'
+ ;;
+ -compose)
+ exec $MOZ_CLIENT_PROGRAM 'xfeDoCommand(composeMessage)'
+ ;;
+ -*) ;;
+ *) USE_EXIST=1 ;;
+ esac
+ fi
+ if [ "${ALREADY_RUNNING}" -eq "1" ] && [ "${USE_EXIST}" -eq "1" ]; then
+ # If there is no command line argument at all then try to open a new
+ # window in an already running instance.
+ if [ -z "$1" ]; then
+ exec $MOZ_CLIENT_PROGRAM "xfeDoCommand(openBrowser)"
+ fi
+
+ # check to make sure that the command contains at least a :/ in it.
+ echo $opt | grep -e ':/' 2>/dev/null > /dev/null
+ RETURN_VAL=$?
+ if [ "$RETURN_VAL" -eq "1" ]; then
+ # if it doesn't begin with a '/' and it exists when the pwd is
+ # prepended to it then append the full path
+ echo $opt | grep -e '^/' 2>/dev/null > /dev/null
+ if [ "${RETURN_VAL}" -ne "0" ]
&------------------------------------------------------
& [ -e `pwd`/$opt ]; then
+ opt="`pwd`/$opt"
+ fi
+ exec $MOZ_CLIENT_PROGRAM "openurl($opt)"
+ fi
+ exec $MOZ_CLIENT_PROGRAM "openurl($opt,new-window)"
+ fi
+ moz_run_program ${1+"$@"}
fi

exit $exitcode
searchSearch Index