473,503 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining an operating system's default browser

Is there a python module which can determine an operating system's
default web browser application.

I would like to use it in the following context: I have a GUI
application where all the documentation is written as html pages. I
wish to have these html help pages open in the default browser when
selected from the application's Help menu

If python can determine the path to the default browser, I can then just
spawn it.

Regards,

John McMonagle


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Feb 9 '06 #1
11 5603
You don't have to determine it. Just os.startfile('page1.html')
and let the OS figure it out.

-Larry Bates
John McMonagle wrote:
Is there a python module which can determine an operating system's
default web browser application.

I would like to use it in the following context: I have a GUI
application where all the documentation is written as html pages. I
wish to have these html help pages open in the default browser when
selected from the application's Help menu

If python can determine the path to the default browser, I can then just
spawn it.

Regards,

John McMonagle

Feb 10 '06 #2
Larry Bates wrote:
You don't have to determine it. Just os.startfile('page1.html')
and let the OS figure it out.


Note that this only works on Windows.

Feb 10 '06 #3
On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:
You don't have to determine it. Just os.startfile('page1.html')
and let the OS figure it out.


Works great for Windows - not available on Unix though.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Feb 10 '06 #4
John McMonagle wrote:
Is there a python module which can determine an operating system's
default web browser application.

I would like to use it in the following context: I have a GUI
application where all the documentation is written as html pages. I
wish to have these html help pages open in the default browser when
selected from the application's Help menu

If python can determine the path to the default browser, I can then just
spawn it.

Regards,

John McMonagle

I think the htmlview command is used for this purpose (displaying html
documentation of applications) on many Linuxes. So you could try
os.system('htmlview'). Given the variety of Unixes (and even Linuxes)
out there this is not a general solution.

So I would try htmlview first. If it does not work, the program could
ask the user for his favourite browser the 1st time he looks at docs,
and save this to a configuration file.
Feb 10 '06 #5

John McMonagle wrote:
Is there a python module which can determine an operating system's
default web browser application.

I would like to use it in the following context: I have a GUI
application where all the documentation is written as html pages. I
wish to have these html help pages open in the default browser when
selected from the application's Help menu

If python can determine the path to the default browser, I can then just
spawn it.

The module webrowser module does this - and I use it for exactly this
purpose. :-)

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
Regards,

John McMonagle


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


Feb 10 '06 #6
John McMonagle wrote:
On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:
You don't have to determine it. Just os.startfile('page1.html')
and let the OS figure it out.


Works great for Windows - not available on Unix though.


Take a look at the desktop module for similar functionality for KDE,
GNOME and the Mac OS X desktop environment (as well as Windows, of
course):

http://www.python.org/pypi/desktop

Paul

Feb 10 '06 #7
John McMonagle <jo****@velseis.com.au> wrote:
Is there a python module which can determine an operating system's
default web browser application.


http://docs.python.org/lib/module-webbrowser.html

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Feb 10 '06 #8
On 10 Feb 2006 03:51:01 -0800, Paul Boddie <pa**@boddie.org.uk> wrote:
John McMonagle wrote:
On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:
> You don't have to determine it. Just os.startfile('page1.html')
> and let the OS figure it out.


Works great for Windows - not available on Unix though.


Take a look at the desktop module for similar functionality for KDE,
GNOME and the Mac OS X desktop environment (as well as Windows, of
course):


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

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.

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.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
Feb 11 '06 #9
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

Feb 11 '06 #10
On 11 Feb 2006 11:44:29 -0800, Paul Boddie <pa**@boddie.org.uk> wrote:
Jorgen Grahn wrote: ....
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


And thanks for mentioning the real name of that mechanism!

.... import mailcap
I guess I shouldn't be surprised that there is a standard module
for that ... ;-)

.... Sadly, when considering my KDE desktop's default browser, inquiring the
application for HTML files yields Mozilla Firefox from my mailcap file.


Yes, but that's only because you haven't configured your mailcap, right?
Which might be a real problem -- most people don't touch their .mailcaps,
especially those who use KDE or Gnome.

Also, sometimes you want a GUI browser to open, and sometimes you want a
console-based one like lynx or w3m. I guess most people who use mailcap do
so because they use console-based mail readers, and thus want the HTML stuff
appear inside the same terminal. Another reason this might be unsuitable
for the OP.

So, while I called it "The One Correct Way" above, I admit it might not be a
very good way ;-)

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
Feb 12 '06 #11
Jorgen Grahn wrote:
On 11 Feb 2006 11:44:29 -0800, Paul Boddie <pa**@boddie.org.uk> wrote:

Indeed. Thanks for reminding me about mailcap/metamail - I used them in
And thanks for mentioning the real name of that mechanism!


Happy memories! ;-)

[...]
import mailcap


I guess I shouldn't be surprised that there is a standard module
for that ... ;-)


It's another stop on the standard library mystery tour!

[...]
Sadly, when considering my KDE desktop's default browser, inquiring the
application for HTML files yields Mozilla Firefox from my mailcap file.


Yes, but that's only because you haven't configured your mailcap, right?
Which might be a real problem -- most people don't touch their .mailcaps,
especially those who use KDE or Gnome.


Going by the following discussion, they abandoned interoperability with
mailcap and went with their own cocktail of new inventions:

https://listman.redhat.com/archives/.../msg00009.html

The above message is where the mailcap-related arguing begins. It boils
over here:

https://listman.redhat.com/archives/.../msg00031.html
Also, sometimes you want a GUI browser to open, and sometimes you want a
console-based one like lynx or w3m. I guess most people who use mailcap do
so because they use console-based mail readers, and thus want the HTML stuff
appear inside the same terminal. Another reason this might be unsuitable
for the OP.

So, while I called it "The One Correct Way" above, I admit it might not be a
very good way ;-)


If there's one "correct" way, it would seem that the xdg people are
always interested in making at least one other "correct" way.
Nevertheless, in defence of the desktop module, its purpose is merely
to "open" things in the context of the current desktop: correct or
standards compliant file type identification doesn't necessarily enter
the picture. ;-)

Still, in the supported environments, desktop.open should do what the
user would expect, given the preference those environments typically
have for their "new and improved" way of doing things involving
configuration dialogues that the user might well have seen (and
probably closed very quickly in horror). Sadly, it doesn't seem to
involve mailcap files, however.

Paul

Feb 12 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
5128
by: Dr.Tube | last post by:
Hi there, I have this web site (www.DrTube.com) which has the following DTD: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> which switches...
3
523
by: Ian Rowland | last post by:
Is there a way, using managed code, to determine the Service Pack of the OS without resorting to registry calls? OSVersion doesn't give this information. It seems the only way is to use the...
18
4895
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
4
2040
by: Rémi | last post by:
Question: How can you determine the character set used by a webpage you built? My understanding of the issue is that the character set used by an HTML file (or any other file, for that matter)...
23
52590
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
19
2106
by: catmansa | last post by:
Is there anyway to determine the present pixel height & width size of a open browser window? :)
1
2341
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Dear Support, I'm not an ASP programmer, however so far by searching the web, I have created this working code: <html> <body> <p> <p> <b>School IP address:</b>
3
1515
Logan1337
by: Logan1337 | last post by:
Hi. I know about System.Diagnostics.Process.Start( url ) to launch a url in the default web browser, but I'm wondering if it's possible to actually get a path to the actual executable that is set as...
4
2396
by: David C. Barber | last post by:
my.computer.printers.defaultprinter doesn't exist in 2005, despite the plethora of examples still out on the web detailing its use. So how can I determine a person's default printer using ASP 2?...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.