For day to day use I tend to use Firefox, and that's my default browser. That's more through "habit" than anything else and I frequently get frustrated by the amount of RAM its using etc.
Occasionally I'll fire up Chrome or Opera, and one day I'll probably switch allegiances.
In the meantime, what annoys me is that if I have (say) Chrome open and click on a link elsewhere (eg in an email) it'll open Firefox because that's my default browser.
I'm sure it would be possible to write a script that checks to see if any browser is open, and sends the request there, only actually starting the default (Firefox) if no browsers are open.
[Actually I think this ought to be the default behaviour for a range of apps; if I have a media player open don't open a different one if I double-click a media file, etc.]
Any suggestions for where I should start?
On 12 Sep 2012, at 09:04, Mark Rogers wrote:
In the meantime, what annoys me is that if I have (say) Chrome open and click on a link elsewhere (eg in an email) it'll open Firefox because that's my default browser.
I'm sure it would be possible to write a script that checks to see if any browser is open, and sends the request there, only actually starting the default (Firefox) if no browsers are open.
[Actually I think this ought to be the default behaviour for a range of apps; if I have a media player open don't open a different one if I double-click a media file, etc.]
Any suggestions for where I should start?
Obvious (and therefore possibly wrong/BFI) answer is to grep the output of ps for common browser names, then run the first one found if it does or your default if it doesn't. For instance something like
#!/bin/sh b=`ps ax | grep '(firefox|chrome|opera)' | grep -v grep | head -1 | awk '{print $5}'` if [ -n $b ] exec $b "$@" else exec firefox "$@" fi
saved in one of the standard locations and set as your default browser would probably do most of the right thing. (of course, I offer no warranty on that, since I mostly just cooked it up off the top of my head)
D.
On 12/09/12 17:58, David Crisp wrote:
#!/bin/sh b=`ps ax | grep '(firefox|chrome|opera)' | grep -v grep | head -1 | awk '{print $5}'` if [ -n $b ] exec $b "$@" else exec firefox "$@" fi
Aside from the missing "then": if [ -n $b ] ; then .. it seems to work well, thanks!
Next silly question: How do I set the default action on opening a URL?
In Ubuntu the "correct" approach is to goto System Settings -> System -> Details -> Default Applications but this only lists the apps installed as alternatives in /var/lib/dpkg/alternatives/x-www-browser. I'm not sure that editing that file is a Good Thing [tm]...
TBH most of my problem is opening links in emails, and as I use Thunderbird that can be set in TB's settings (and seems to work well).
It has got me thinking though that the update-alternatives concept, good as it is, could be improved by checking to see if one of the "alternatives" is already open and re-using it first rather than starting the default alternative. It wouldn't be as simple as just having a symlink to the chosen default but could just be a symlink to a script that worked out the alternatives as per David's script above. I think this needs a bit more thought/work...
Thanks again, though; the simple script above is already pretty close to what I need.
Mark