Determining an operating system's default browser

Paul Boddie paul at boddie.org.uk
Sat Feb 11 14:44:29 EST 2006


Jorgen Grahn wrote:
>

[desktop module]

> Note that those do not, of course, work on all Unices.

Correct: they work only for the stated desktop environments.

> On my machines, there is One Correct Way of doing these things, and that's
> to look in the MIME support/configuration files (~/.mailcap, and so on),
> first for the user, then system-wide. Something there might tell you what
> program should handle text/html content.

Indeed. Thanks for reminding me about mailcap/metamail - I used them in
a project about ten years ago, and I suppose not having any
opportunities to use them in the intervening period probably pushed
them to the back of my mind.

> This mechanism is widespread under Unix, I think ... but I don't know if
> there is a general interface to it, or a Python interface.

Here's an example:

import mailcap
command, entry = mailcap.findmatch(mailcap.getcaps(), "text/html")

Here's another more comprehensive set of examples:

http://effbot.org/librarybook/mailcap.htm

Sadly, when considering my KDE desktop's default browser, inquiring the
application for HTML files yields Mozilla Firefox from my mailcap file.
What I've discovered is that the issue of an URL-opening application is
often quite separate from an appropriate application to open a file of
a given type. Perhaps I should call desktop.open something like
desktop.urlopen instead, since that name arguably describes the purpose
of the function more accurately.

Paul




More information about the Python-list mailing list