Click to See Complete Forum and Search --> : FireFox Multiple Windows by Clicking an Icon


nko
04-22-2004, 08:05 PM
Alright, I've run in to the problem a number of times where I've got Mozilla (from here on out I'll refer to FireFox) open, and I want to click the convenient little icon in my task bar / shortcut menu to fire up another window, but when I do, it spits out an area to use a different profile! Searching the net didn't supply any nice, tidy ways of doing things, so I set about doing it my OWN way; I wrote a Python script.

Below is a little script that checks all the running processes to check if firefox is running. If it is, it launches a new window and loads the "about:blank" page (a blank page). If it isn't running, it just launches firefox. Please note that I'm only a wannabe programmer / scriptor, and this is the first truely useful-for-more-than-just-me thing I've ever written, so I'm feelin' pretty proud :-).

Here's the code:

#! /usr/bin/python

import os

thing = os.popen('ps -A | grep firefox-bin').read()

if thing == "":
already_loaded = "no"
else:
already_loaded = "yes"
if already_loaded == 'no':
os.popen('mozilla-firefox')
if already_loaded == 'yes':
os.popen('mozilla-firefox -remote "openurl("about:blank", new-window)"')


Now, to use this, just cut and paste it in to a file, then at the command line, run "chmod a+x the_file_name". Now, make your shortcut point to this file, and voila! The shortcut works, every time!

I put mine in /usr/local/bin, and called it "load-firefox", in case you're new here, and wondering where a decent place to put the file might be. If anyone, even the newest of users who has this problem has any questions, please ask, so we can stamp out this problem!

BTW, you have to have Python installed. Most people do, even if they don't know it. Out of curiosity, can anyone show me how to do exactly this in Ruby, Perl, or BASH? Maybe another language? It'd be cool to have someone do it in assembler.

dboyer
04-22-2004, 08:18 PM
Here's a bash script that opens a new tab upon reopening firefox:


#!/bin/bash
/usr/firefox/firefox -remote "openURL($@, new-tab)" ||
exec /usr/firefox/firefox "$@";


i actually had a lot of problems getting this to cooperate too... seems like it ought to be simple to do, but oh well....

as far as where to put it, anywhere in your $PATH should work... or you can put it in your homedirectory if you odn't mind specifying the path each time you ran it (and only have one user :))

nko
04-22-2004, 08:20 PM
oops... my formatting got messed up. Here it is attached as a txt file.

I first tried making it just launch a new window, but then if there wasn't already a window open, it'd tell me that firefox wasn't running, and I'd end up with nothing but a useless icon.

nko
04-22-2004, 08:22 PM
Wait... I get it. So yours attempts to launch a new window, and if that's unsuccessful, it launches firefox?

bwkaz
04-23-2004, 06:55 PM
Originally posted by nko
oops... my formatting got messed up. (Psst! If you put and tags around your code, the indentation won't be lost... ;))

nko
04-23-2004, 07:00 PM
Good to know! I've seen that done a lot, but I just don't post often enough to remember these things.

dboyer
04-24-2004, 12:24 AM
yup, theres an or statement there... it goes to evaluate the OR statement... if the first half succeeds (and returns a 1 or whatever) then it doesn't bother with the second half...

ol' c programmers trick.. hehe