LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Where/How is Homepage URL stored in Mozilla Firefox 0.9? (https://www.linuxquestions.org/questions/linux-software-2/where-how-is-homepage-url-stored-in-mozilla-firefox-0-9-a-196569/)

DiscoGranny 06-22-2004 07:24 PM

Where/How is Homepage URL stored in Mozilla Firefox 0.9?
 
Okay, I worked up a nice little script to circumvent the profiles hassle when trying to run multiple instances of firefox 0.9.

My script does one of these four things:
If firefox isn't running at all and a URL isn't supplied, launch a new instance
If firefox isn't running at all and a URL is supplied, launch a new instance that opens the URL
If firefox is running and a URL is supplied, open URL in a new tab
If firefox is running and a URL isn't supplied, open a new tab that's blank

the last condition is the tricky one. I don't want it to open blank. I would rather have it open up the home page. I have scoured the 'net and can't find the command that will accomplish this or the location (either file or variable) that stores what the homepage URL is. Any help?

*Note: for the homepage, I tried $home. This doesn't work. Just remove it (be sure to leave the comma), if you just want it to open blank.*

Code:

#!/bin/sh
# Works for Firefox 0.9
# Written by Robert Mullenix, June 2004

MOZILLA="/usr/share/firefox/firefox"
# Find out Firefox is open already
if $MOZILLA -a firefox -remote "ping()" 2>/dev/null
then
  if [ -z $1 ]
  then
# instance already opened, open new tab
    $MOZILLA -a firefox -remote "openURL($home,new-tab)" &
  else
# instance already opened, launch URL $1 in new tab
    $MOZILLA -a firefox -remote "openURL($1,new-tab)" &
  fi
else
  if [ -z $1 ]
  then
#  no URL present, just open firefox
    $MOZILLA &
  else
#  no instances exist, open a new window with URL $1
    $MOZILLA $1 &
  fi
fi
exit 1


Axion 06-22-2004 08:15 PM

all i could find was this, did you see it?

http://www.deftone.com/blogzilla/arc...n_new_tab.html

DiscoGranny 06-22-2004 10:02 PM

I missed that. It's a good link and it works for mozilla, but it won't work for firefox. I extracted the comm.jar in firefox/chrome and then went into the content directory, but right away you'll notice that there is no navigator folder or navigator.js.

Whatever causes mozilla to open up a new tab isn't there...

good idea, though

DiscoGranny 06-22-2004 10:23 PM

Okay, I did some snooping to try and figure out where Firefox puts the homepage. It stores it in ~/.mozilla/firefox/{profile_name}.ima/prefs.js

Since I use the default profile, I did some scripting and came up with this. It may not work for everyone, but it works for me:

Code:

#!/bin/sh
# firefox.sh
# Works for Firefox 0.9
# Written by Robert Mullenix, June 2004

HOMEPAGE=`cat ~/.mozilla/firefox/default.ima/prefs.js | grep browser.startup.homepage\" | cut -f 4 -d \"`
MOZILLA="/usr/share/firefox/firefox"
# Find out Firefox is open already
if $MOZILLA -a firefox -remote "ping()" 2>/dev/null
then
  if [ -z $1 ]
  then
# instance already opened, open new tab
    $MOZILLA -a firefox -remote "openURL($HOMEPAGE,new-tab)" &
  else
# instance already opened, launch URL $1 in new tab
    $MOZILLA -a firefox -remote "openURL($1,new-tab)" &
  fi
else
  if [ -z $1 ]
  then
#  no URL present, just open firefox
    $MOZILLA &
  else
#  no instances exist, open a new window with URL $1
    $MOZILLA $1 &
  fi
fi
exit 1


Axion 06-22-2004 10:50 PM

You're right, it won't work for everyone because the "default.ima" folder is random. For instance, here it is named "default.6ss". Would be nice if you could have the script guess the ending

DiscoGranny 06-22-2004 11:54 PM

This'll do the trick:
I have really gotten to like the grep cut combo, but it seems a little clunky...

Modifications in bold

Code:

# firefox.sh
# Works for Firefox 0.9
# Written by Robert Mullenix, June 2004

PROFILEPATH=`cat ~/.mozilla/firefox/profiles.ini | grep Path | cut -f 2 -d =`
HOMEPAGE=`cat ~/.mozilla/firefox/$PROFILEPATH/prefs.js | grep browser.startup.homepage\" | cut -f
MOZILLA="/usr/share/firefox/firefox"
# Find out Firefox is open already
if $MOZILLA -a firefox -remote "ping()" 2>/dev/null
then
  if [ -z $1 ]
  then
# instance already opened, open new tab
    $MOZILLA -a firefox -remote "openURL($HOMEPAGE,new-tab)" &
  else
# instance already opened, launch URL $1 in new tab
    $MOZILLA -a firefox -remote "openURL($1,new-tab)" &
  fi
else
  if [ -z $1 ]
  then
#  no URL present, just open firefox
    $MOZILLA &
  else
#  no instances exist, open a new window with URL $1
    $MOZILLA $1 &
  fi
fi
exit 1


Axion 06-24-2004 02:30 AM

Odd, the last script does not work. the grep by itself works and extracts default.6ss from the ini file, but the full path to the prefs file is missing the $PROFILEPATH subdir...the script thinks my prefs.js file is located at "/home/axion/.mozilla/firefox//prefs.js"...default6ss is not added for some reason, though the same grep works outside of the script...

calt129 07-19-2004 02:33 PM

a tiny improvement
 
This should work for you, it may be inefficient (2 cut's :P) but it works

Code:

# firefox.sh
# Works for Firefox 0.9
# Written by Robert Mullenix, June 2004
# Modified by Cuneyt Yilmaz, June 2004

PROFILEPATH=`cat ~/.mozilla/firefox/profiles.ini | grep Path | cut -f 2 -d =`
HOMEPAGE=`cat ~/.mozilla/firefox/$PROFILEPATH/prefs.js | grep browser.startup.homepage\" | cut -f 2 -d , | cut -f 2 -d \"`
# I'm using the following, but hard-coded path may be better for some
#MOZILLA=`which firefox`
MOZILLA=/usr/local/firefox/firefox
URL=$1

# if no URL is given, use the home page
if [ -z $URL ]; then
  URL=$HOMEPAGE
fi


$MOZILLA -a firefox -remote "ping()" 2>/dev/null
if [ $? -eq 0 ]; then
  # it's already running
  $MOZILLA -a firefox -remote "openURL($URL,new-tab)" &
else
  # not running
  $MOZILLA "$URL" &
fi
exit 1



All times are GMT -5. The time now is 05:01 PM.