LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Mozilla Firefox open new window script (http://www.linuxquestions.org/questions/linux-software-2/mozilla-firefox-open-new-window-script-189314/)

Pathian 06-03-2004 12:53 PM

Mozilla Firefox open new window script
 
Hello all, I was wondering if anyone has had any luck with the script for the firefox launcher that is supposed to open I new window from an existing session instead of popping up that "select user profile" screen. I copied the script from the mozilla website and pointed it at firefox

#!/bin/sh

export MOZILLA_FIVE_HOME="/usr/lib/mozilla-firefox"

url="$1"
if [ "x$url" = "x" ]; then
url="about:blank"
fi

if $MOZILLA_FIVE_HOME/mozilla-xremote-client openURL\("$url"\); then
exit 0
fi
exec $MOZILLA_FIVE_HOME/firefox "$url"

but whenever I launch the script, instead of opening a new window, it merely takes the current window (or tab) and sends it to about:blank (or if I supply a URL, it sends the current tab to that URL). When I was using Mozilla 1.6 I used this script to get the desired behavior...

moz="/usr/lib/mozilla-1.6/mozilla-bin"

isRunning=`2>&1 $moz -remote ping`
case $isRunning in
# Start a new mozilla session
"No running window found." )
$moz "$*"
;;

# Spawn a new mozilla window from the existing session
"Failed to send command." )
$moz -remote "OpenURL ( "$*" , new-window)"
;;

# Dude, something's wrong.
* )
echo "This was the return value: $isRunning"
echo "d'oh"
;;
esac

Does anyone know how to adjust the firefox script so that a new window opens from the current session when the launcher is run? Thanks

david_ross 06-03-2004 01:05 PM

I think firefox takes the same "new-window" argument to openURL that mozilla does.

SADANA 06-20-2004 04:25 PM

i edited the shell script, that came with mozila-1.5, so that i can run firefox just the way i want it... actually all i did was set the paths to point to firefox and removed that mail and compose options, and now it works :-) here it goes, enjoy:


#!/bin/sh
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#

##
## Usage:
##
## $ mozilla
##
## This script is meant to run a mozilla program from the mozilla
## rpm installation.
##
## The script will setup all the environment voodoo needed to make
## mozilla work.

cmdname=`basename $0`

## don't leave any core files around
ulimit -c 0

##
## Variables
##
MOZ_DIST_BIN="/usr/lib/mozilla-firefox"
MOZ_PROGRAM="/usr/lib/mozilla-firefox/firefox-bin"
MOZ_CLIENT_PROGRAM="/usr/lib/mozilla-firefox/mozilla-xremote-client"

##
## Set LD_LIBRARY_PATH
##
if [ "$LD_LIBRARY_PATH" ]
then
LD_LIBRARY_PATH=/usr/lib/mozilla-firefox:/usr/lib/mozilla-firefox/plugins:$LD_LIBRARY_PATH
else
LD_LIBRARY_PATH=/usr/lib/mozilla-firefox:/usr/lib/mozilla-firefox/plugins
fi
export LD_LIBRARY_PATH

##
## Make sure that we set the plugin path for backwards compatibility
##
MOZ_PLUGIN_PATH=/usr/lib/mozilla-firefox/plugins
export MOZ_PLUGIN_PATH

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
}

# check to see if there's an already running instance or not
ALREADY_RUNNING=`check_running`

# If there is no command line argument at all then try to open a new
# window in an already running instance.
if [ "${ALREADY_RUNNING}" -eq "1" ] && [ -z "$1" ]; then
exec $MOZ_CLIENT_PROGRAM "xfeDoCommand(openBrowser)" 2>/dev/null >/dev/null
fi

# if there's no command line argument and there's not a running
# instance then just fire up a new copy of the browser
if [ -z "$1" ]; then
exec $MOZ_PROGRAM 2>/dev/null >/dev/null
fi

unset RETURN_VAL

# If there's a command line argument but it doesn't begin with a -
# it's probably a url. Try to send it to a running instance.

USE_EXIST=1
opt="$1"

if [ "${USE_EXIST}" -eq "1" ] && [ "${ALREADY_RUNNING}" -eq "1" ]; then
# 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)" 2>/dev/null >/dev/null
fi
# just pass it off if it looks like a url
exec $MOZ_CLIENT_PROGRAM "openurl($opt,new-window)" 2>/dev/null >/dev/null
fi

exec $MOZ_PROGRAM ${1+"$@"}

warren1715 07-07-2004 04:06 PM

firefox - new window
 
I wrote this to solve that problem. I start firefox-agent instead of firefox for all browser applications. You may need to make slight changes to match your system

--UPDATED for version 0.9.1--

#!/bin/sh
#
# Script name: /usr/bin/firefox-agent
# Launches firefox in a new window (or tab)
# Written by *****. License 'GPL'
#
# Tested on firefox 0.9.1 using mandrake 10.0
#
PIDOF='/sbin/pidof' # Location of 'pidof' program
DIST_BIN='/usr/local/firefox' # where firefox is installed
WINDOWTYPE='new-window' # Use 'new-window' or 'new-tab', your preference
#
# You should not need to change below.
#
PREFS="${HOME}/.mozilla/firefox/`ls ${HOME}/.mozilla/firefox | grep default | sed -e 's/\///g'`/prefs.js"
MOZ_CLIENT_PROGRAM=$DIST_BIN/mozilla-xremote-client
BROWSER='firefox-bin'
HOMEURL=`cat $PREFS | grep -e \"browser.startup.homepage\" | sed -e 's/\(.*\,\ \"\)\(.*\)\(\".*\)/\2/g'`
#
if test "`$PIDOF $BROWSER`" = "" ; then
exec $DIST_BIN/firefox "$1"
else
if test "$1" = "" ; then
exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$HOMEURL",$WINDOWTYPE)"
else
exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$1",$WINDOWTYPE)"
fi
fi

Cerbere 07-08-2004 12:20 AM

Why the script? Is hitting 'ctrl+n' too difficult?

Enjoy!
--- Cerbere

david_ross 07-08-2004 12:50 PM

Some applications such as e-mail clients need a way to pass urls to the browser - hence the reason for the script. Personally I just use crtl+n or ctrl+t when browsing normally though.

slaw219 07-11-2004 05:21 PM

I'm trying to use this shell-script, but have no idea how to create it or use it. Could somebody explain how I use this script or where to find info on creating scripts?
Thanks :newbie:

webazoid 07-11-2004 07:16 PM

Re: firefox - new window
 
Quote:

Originally posted by warren1715
I wrote this to solve that problem. I start firefox-agent instead of firefox for all browser applications. You may need to make slight changes to match your system

--UPDATED for version 0.9.1--

#!/bin/sh
#
# Script name: /usr/bin/firefox-agent
# Launches firefox in a new window (or tab)
# Written by *****. License 'GPL'
#
# Tested on firefox 0.9.1 using mandrake 10.0
#
PIDOF='/sbin/pidof' # Location of 'pidof' program
DIST_BIN='/usr/local/firefox' # where firefox is installed
WINDOWTYPE='new-window' # Use 'new-window' or 'new-tab', your preference
#
# You should not need to change below.
#
PREFS="${HOME}/.mozilla/firefox/`ls ${HOME}/.mozilla/firefox | grep default | sed -e 's/\///g'`/prefs.js"
MOZ_CLIENT_PROGRAM=$DIST_BIN/mozilla-xremote-client
BROWSER='firefox-bin'
HOMEURL=`cat $PREFS | grep -e \"browser.startup.homepage\" | sed -e 's/\(.*\,\ \"\)\(.*\)\(\".*\)/\2/g'`
#
if test "`$PIDOF $BROWSER`" = "" ; then
exec $DIST_BIN/firefox "$1"
else
if test "$1" = "" ; then
exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$HOMEURL",$WINDOWTYPE)"
else
exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$1",$WINDOWTYPE)"
fi
fi

what's firefox agent?

webazoid 07-11-2004 07:21 PM

i need help w/ running the script too!:scratch:

slaw219 07-11-2004 08:52 PM

he simply made a script called firefox-agent and linked all his launchers to firefox-agent instead of firefox

I think I know how to make scripts work now...however when I tried to make this file it didn't work..nothing opens. It will open the first instance but won't open a second...here's my code I have my firefox installed in /opt/firefox/

Code:

cript name: /usr/bin/firefox-agent
 # Launches firefox in a new window (or tab)
 # Written by *****. License 'GPL'
 #
 # Tested on firefox 0.9.1 using mandrake 10.0
 #
 PIDOF='/sbin/pidof' # Location of 'pidof' program
 DIST_BIN='/opt/firefox' # where firefox is installed
 WINDOWTYPE='new-tab' # Use 'new-window' or 'new-tab', your preference
 #
 # You should not need to change below.
 #
 PREFS="${HOME}/.mozilla/firefox/`ls ${HOME}/.mozilla/firefox | grep default | sed -e 's/\///g'`/prefs.js"
 MOZ_CLIENT_PROGRAM=$DIST_BIN/mozilla-xremote-client
 BROWSER='firefox-bin'
 HOMEURL=`cat $PREFS | grep -e \"browser.startup.homepage\" | sed -e 's/\(.*\,\ \"\)\(.*\)\(\".*\)/\2/g'`
 #
 if test "`$PIDOF $BROWSER`" = "" ; then
 exec $DIST_BIN/firefox "$1"
 else
 if test "$1" = "" ; then
 exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$HOMEURL",$WINDOWTYPE)"
 else
 exec $MOZ_CLIENT_PROGRAM -a firefox "openURL("$1",$WINDOWTYPE)"
 fi
 fi



Thanks =/

p-static 07-11-2004 11:52 PM

Actually, the latest firefox doesn't seem to have problems with multiple windows open, thus making all of this kind of pointless.

BluePyre 07-12-2004 04:19 AM

To make a new script:
Save the script into a new text file. Call it whatever you like, with whatever extension, it makes no difference.
From a terminal, type:

chmod a+x scriptFileName

and then to run the script, a simple

./scriptFileName

Obviously replace scriptFileName with the name of your script

warren1715 07-13-2004 10:24 PM

I wrote this because I got tired of clicking on links from other applications (such as email) while the browser was already open and getting that dreaded profile manager (^N can't do that). The post above does not work with version 0.8, please check your version. I have another script version for 0.8 if you want. To make the script work, copy to a text editor and save the file as firefox-agent in a directory in your path (you may have to log on as root). Change the properties of the saved file and make it executable. Edit the file to match your system (pidof and firefox locations must be correct). To test run firefox-agent. To use the script, associate URL's with firefox-agent.

0.8 version:

#!/bin/sh
#
# Script name: /usr/bin/firefox-agent
# Launches firefox in a new window (or tab)
# Written by *****. License 'GPL'
#
# Tested on FireFox 0.8 using mandrake 10.0
#
PIDOF='/sbin/pidof' # Location of 'pidof' program
DEFAULTBROWSER='/usr/local/firefox/firefox' # Locaion of firefox
WINDOWTYPE='new-window' # Use 'new-window' or 'new-tab', your preference
#
# You should not need to change below.
#
BROWSER='firefox-bin'
PREFS="${HOME}/.phoenix/default/`ls ${HOME}/.phoenix/default`/prefs.js"
HOMEURL=`cat $PREFS | grep -e \"browser.startup.homepage\" | sed -e 's/\(.*\,\ \"\)\(.*\)\(\".*\)/\2/g'`
#
if test "`$PIDOF $BROWSER`" = "" ; then
exec $DEFAULTBROWSER "$1"
else
if test "$1" = "" ; then
exec $DEFAULTBROWSER -remote openURL"("$HOMEURL",$WINDOWTYPE)"
else
exec $DEFAULTBROWSER -remote openURL"("$1",$WINDOWTYPE)"
fi
fi

slaw219 07-14-2004 12:18 AM

I'm looking for the 9.1 script...9.2 has been out for a while but it still says 9.1 for linux. I may just have to deal with it..or make my own, but that seems a lot more complicated than I'm willing to commit :newbie:

webazoid 07-14-2004 01:06 AM

a recent nightly build of the ff trunk doesn't have that problem anymore.


All times are GMT -5. The time now is 09:45 AM.