Linux default browser / Java
Some desktop systems know the concepts of "default browser" and "default
mailer", programs that are launched automatically if URLs with certain
protocols (http, https, mailto) are to be handled. These notions are
of interest, among others, for Java programmers.
Java: In Java 6 the
class Desktop supplies an API for launching (among others) the
default browser and mailer in a system independent way.
So much for theory. While this works fine under Windows and MacOS, it is
not guaranteed to work under Linux or Solaris. Here Java 6 relies solely on
the existence of a set of GNOME libraries. If they are
missing, the Desktop API won't work. This means that on pure
GNOME systems the API will be supported, while on others you may have to
install some additional packages. Unfortunately the documentation doesn't
say which libraries Java 6 is looking for. My experiments showed
that at least libgnome and gconf are needed,
probably others required by these as well. On pure KDE systems these
libraries will likely not be present, so if you want to utilize the
Desktop there, you'll have to install the corresponding rpm
packages. [1] Furthermode, it appears to be
necessary to assign a default browser and mailer once to make the whole
thing work. file: URLs are not passed to the
browser.
Browser/mailer coupling:
Apparently not only Java, but also the family of Mozilla products
uses the GNOME mechanism (at least with Firefox 3). Thus the presence
of the libraries has an additional advantage: Clicking on a
mailto: link in Firefox automatically activates the
default mailer, and clicking on a http link in Thunderbird activates
the default browser, both without the need to change any
options in the prefs.js files.
Setting: The default browser may not always be the one you want. On some desktop
systems the defaults can be set via the GUI. If there is no such facility,
one could try to change the setting by the program itself, for
example, let Firefox make itself the standard browser. But this also
doesn't work in all cases. However, there is always one last resort: The
program gconftool-2 , which is part of the gconf
package. It allows assigning a default application to every single protocol
(http, https, mailto etc.). Exactly for this reason it isn't very
convenient. The following scripts stdbrowser
and stdmail provide a more comfortable tool
for changing the default settings. The latter is simply a symbolic link to
the former.
Usage:
stdbrowser -h |
Print a short help |
stdbrowser -p |
Print path of the default browser |
stdbrowser -s path |
Set the default browser. If path is a
simple name, the program is looked up using $PATH.
|
stdbrowser -k |
Kill a running default browser (if it hangs). |
stdbrowser URL |
Launch the default browser with the given URL. |
If called with the option -s , the script assigns the
new browser to all appropriate protocols (http, https, ftp, chrome). If the
same script is called as stdmail , everything said above refers to
the default mailer. Here a mail address is supplied with the
optionless call. The default mailer is assigned to the protocols feed,
mailto, news, nntp, snews.
Option -k can be used if the program hangs and can't be
kill by means of the GUI (a well-know browser misbehaviour). The script
issues the rather brutal command
pkill -KILL name , where
name is the base name of the program.
The optionless call simply means an indirect start of the default
application. This may add some flexibility to your system. For example, you
could use stdmail (instead of Thunderbird) as the application
handling "mailto:" links in Firefox. If the default mailer is changed
afterwards, Firefox will use the new setting immediately, without its
configuration having to be changed.
For installation, unpack the script in an arbitrary directory. Go
to this directory and create a symbolic link using the command
ln -s stdbrowser stdmail
Called under the name stdmail , the script will handle
the default mailer.
[1] Good luck!
|