Determining an operating system's default browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John McMonagle

    #1

    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.

  • Larry Bates

    #2
    Re: Determining an operating system's default browser

    You don't have to determine it. Just os.startfile('p age1.html')
    and let the OS figure it out.

    -Larry Bates


    John McMonagle wrote:[color=blue]
    > 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
    >
    >
    >
    >[/color]

    Comment

    • sjdevnull@yahoo.com

      #3
      Re: Determining an operating system's default browser

      Larry Bates wrote:[color=blue]
      > You don't have to determine it. Just os.startfile('p age1.html')
      > and let the OS figure it out.[/color]

      Note that this only works on Windows.

      Comment

      • John McMonagle

        #4
        Re: Determining an operating system's default browser

        On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:[color=blue]
        > You don't have to determine it. Just os.startfile('p age1.html')
        > and let the OS figure it out.[/color]

        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.

        Comment

        • Juho Schultz

          #5
          Re: Determining an operating system's default browser

          John McMonagle wrote:[color=blue]
          > 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
          >
          >
          >[/color]
          I think the htmlview command is used for this purpose (displaying html
          documentation of applications) on many Linuxes. So you could try
          os.system('html view'). 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.

          Comment

          • Fuzzyman

            #6
            Re: Determining an operating system's default browser


            John McMonagle wrote:[color=blue]
            > 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.
            >[/color]

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

            Fuzzyman
            http://www.voidspace.org.uk/python/index.shtml
            [color=blue]
            > Regards,
            >
            > John McMonagle
            >
            >
            >
            >
            > --
            > This message has been scanned for viruses and
            > dangerous content by MailScanner, and is
            > believed to be clean.[/color]

            Comment

            • Paul Boddie

              #7
              Re: Determining an operating system's default browser

              John McMonagle wrote:[color=blue]
              > On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:[color=green]
              > > You don't have to determine it. Just os.startfile('p age1.html')
              > > and let the OS figure it out.[/color]
              >
              > Works great for Windows - not available on Unix though.[/color]

              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):



              Paul

              Comment

              • Sion Arrowsmith

                #8
                Re: Determining an operating system's default browser

                John McMonagle <johnmc@velseis .com.au> wrote:[color=blue]
                >Is there a python module which can determine an operating system's
                >default web browser application.[/color]

                Source code: Lib/webbrowser.py The webbrowser module provides a high-level interface to allow displaying web-based documents to users. Under most circumstances, simply calling the open() function f...


                --
                \S -- siona@chiark.gr eenend.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

                Comment

                • Jorgen Grahn

                  #9
                  Re: Determining an operating system's default browser

                  On 10 Feb 2006 03:51:01 -0800, Paul Boddie <paul@boddie.or g.uk> wrote:[color=blue]
                  > John McMonagle wrote:[color=green]
                  >> On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:[color=darkred]
                  >> > You don't have to determine it. Just os.startfile('p age1.html')
                  >> > and let the OS figure it out.[/color]
                  >>
                  >> Works great for Windows - not available on Unix though.[/color]
                  >
                  > 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):[/color]

                  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.dyn dns.org> R'lyeh wgah'nagl fhtagn!

                  Comment

                  • Paul Boddie

                    #10
                    Re: Determining an operating system's default browser

                    Jorgen Grahn wrote:[color=blue]
                    >[/color]

                    [desktop module]
                    [color=blue]
                    > Note that those do not, of course, work on all Unices.[/color]

                    Correct: they work only for the stated desktop environments.
                    [color=blue]
                    > 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.[/color]

                    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.
                    [color=blue]
                    > 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.[/color]

                    Here's an example:

                    import mailcap
                    command, entry = mailcap.findmat ch(mailcap.getc aps(), "text/html")

                    Here's another more comprehensive set of examples:



                    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

                    Comment

                    • Jorgen Grahn

                      #11
                      Re: Determining an operating system's default browser

                      On 11 Feb 2006 11:44:29 -0800, Paul Boddie <paul@boddie.or g.uk> wrote:[color=blue]
                      > Jorgen Grahn wrote:[/color]
                      ....[color=blue][color=green]
                      >> 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.[/color]
                      >
                      > Indeed. Thanks for reminding me about mailcap/metamail - I used them in[/color]

                      And thanks for mentioning the real name of that mechanism!

                      ....[color=blue]
                      > import mailcap[/color]

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

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

                      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.dyn dns.org> R'lyeh wgah'nagl fhtagn!

                      Comment

                      • Paul Boddie

                        #12
                        Re: Determining an operating system's default browser

                        Jorgen Grahn wrote:[color=blue]
                        > On 11 Feb 2006 11:44:29 -0800, Paul Boddie <paul@boddie.or g.uk> wrote:[color=green]
                        > >
                        > > Indeed. Thanks for reminding me about mailcap/metamail - I used them in[/color]
                        >
                        > And thanks for mentioning the real name of that mechanism![/color]

                        Happy memories! ;-)

                        [...]
                        [color=blue][color=green]
                        > > import mailcap[/color]
                        >
                        > I guess I shouldn't be surprised that there is a standard module
                        > for that ... ;-)[/color]

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

                        [...]
                        [color=blue][color=green]
                        > > Sadly, when considering my KDE desktop's default browser, inquiring the
                        > > application for HTML files yields Mozilla Firefox from my mailcap file.[/color]
                        >
                        > 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.[/color]

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



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


                        [color=blue]
                        > 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 ;-)[/color]

                        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

                        Comment

                        Working...