tags:

views:

230

answers:

3

How do I find out the user's "preferred web browser", if they're using Gnome desktop environment? (I want to open a webpage, I don't need to know which browser the user prefers.)

Some background: I'm trying to open a browser window (my homepage) with my Java app.

  1. if Java version is 1.6+, use Desktop.browse(url);
  2. otherwise, use BareBonesBrowserLaunch.openURL(url) - that means checking the environment and starting a browser with Runtime.getRuntime().exec()

Method 2 works on Windows just fine; and opens a browser on Linux. However, it's the first browser that it finds (in my case, looks for Firefox first). In Gnome desktop environment (e.g. Ubuntu Linux has that by default), you could set your "Preferred Applications" for e-mail, www browsing etc; I believe this information is accesible somewhere. How can I find out which is the user's preferred browser?

In other words: where does Gnome store the "Preferred Browser" setting?

+1  A: 

The "default browser" setting is in ~/.gconf/desktop/gnome/url-handlers/http/%gconf.xml Here's mine:

<?xml version="1.0"?>
<gconf>
    <entry name="command" mtime="1243616896" type="string">
 <stringvalue>opera %s</stringvalue>
    </entry>
</gconf>

The <stringvalue/> is the command I was looking for.

(Found this out after a while - and forgot to post the question.)

Piskvor
+2  A: 

Consider using gnome-open.

I use this on Gnome and kfmclient on KDE.

Michael Brewer-Davis
That's much cleaner (and simpler) than what I found; thanks a lot.
Piskvor
+4  A: 

The most portable way to open a file or URL in Linux desktop is xdg-open.

http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html

Danilo Piazzalunga
Which just calls `gnome-open`/`kfmclient`/`exo-open`/etc, depending on what's available. And if `xdg-open` does not exist, `$BROWSER` is the next one to check.
grawity
Yes, and this is why `xdg-open` is better: it works on every standards-compliant Linux desktop.
Danilo Piazzalunga