How do you automatically open the default browser?

Linux specific forum
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

How do you automatically open the default browser?

Post by DoubleDutch »

In windows you just:

Code: Select all

RunProgram(page$)
(with page$ being an address of a webpage)

and it will open IE, etc and display the page.

How do you do this in Linux?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 576
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Post by bembulak »

you could try to read the Enviroment-Variabel "BROWSER", but I'm not sure yet.

I've written a code, some weeks ago and this worked good for me (but still I'm not sure if it will be the right solution):

Code: Select all

Case #btn_visitWeb
                	CompilerSelect #PB_Compiler_OS
                		CompilerCase #PB_OS_Linux
	                		RunProgram("www-browser", #BEMBURL, "")
	                	CompilerCase #PB_OS_MacOS
	                		RunProgram("www-browser", #BEMBURL, "")
	                	CompilerCase #PB_OS_Windows
	                		RunProgram(#BEMBURL)
	                CompilerEndSelect
cheers,

bembulak
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thanks for the help, but it didn't work on 'Kubuntu'. :(
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

If you've got a modern distribution:

Code: Select all

RunProgram("xdg-open", "http://www.noname-development.de", "")
If using an ancient distribution:
KDE:

Code: Select all

RunProgram("kfmclient", " exec http://www.noname-development.de", "")
GNOME:

Code: Select all

RunProgram("gnome-open", "http://www.noname-development.de", "")
Image Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Wishmaster: Thanks for that - I'll try it.

I managed to get this working:

Code: Select all

Procedure Internet(page$)
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    If RunProgram(page$)=#False
      Warning("Unable to start Internet Explorer.  Please check your system."+Chr(#CR)+Chr(#CR)+"Or contact Cut the Costa!")
    EndIf
  CompilerElse
    browser$=Trim(GetEnvironmentVariable("BROWSER"))  ; apparently this is the new "standard"?
    If browser$=""
      If Trim(GetEnvironmentVariable("KDE_FULL_SESSION"))<>""
        browser$="konqueror"
      Else
        browser$="nautilus"		; assume gnome if not KDE, may need to add more?
      EndIf
    EndIf
    If RunProgram(browser$,page$,"")=#False
      Warning("Unable to start the web browser.  Please check your system."+Chr(#CR)+Chr(#CR)+"Or contact Cut the Costa!")
    EndIf
  CompilerEndIf
EndProcedure
"Warning" just displays a message dialog...
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

Your solution is definitely not a good one:
1) It only takes care of KDE and GNOME although there are many other desktop envrionments/window managers
2) The $BROWSER is not a standard. E.g. on OpenSUSE it doesn't exist.
3) On KDE the default browser can also be Firefox just like on GNOME the user's preferred browser could be Opera.

Portland is the new standard for DE-independend programming :wink:

==> http://portland.freedesktop.org/wiki/
Image Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Wishmaster: 'xdg-open' didn't for for me on kubuntu 6.10, but the rest of the stuff you wrote about worked fine.

Here is the merged procedure, it tried 'xdg-open' and if it fails, it falls back to the older methods (trying the 'browser' variable first).

Code: Select all

Procedure Internet(page$)
  message$="Unable to start the web browser."
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    If RunProgram(page$)=#False
      Warning(message$)
    EndIf
  CompilerElse
    If RunProgram("xdg-open",page$,"")=#False
      browser$=Trim(GetEnvironmentVariable("BROWSER"))
      If browser$=""
        If RunProgram("gnome-open",page$,"")=#False
          If RunProgram("kfmclient","exec "+page$,"")=#False
            If RunProgram("www-browser",page$,"")=#False
              Warning(message$)
            EndIf
          EndIf
        EndIf
      Else
        If RunProgram(browser$,page$,"")=#False
          Warning(message$)
        EndIf
      EndIf
    EndIf
  CompilerEndIf
EndProcedure
[Edited to stop using KDE check]

This works on Kubuntu (KDE based), no problems.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

Yes, that's a good idea.
To get xdg-open working, you can install xdg-utils.

In the next (K)Ubuntu release xdg-utils will perhaps be installed by default (at the moment I'm asking my way though the Ubuntu community :wink: ).
Image Image
Post Reply