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.
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.