Page 1 of 1
How do you automatically open the default browser?
Posted: Tue Jan 02, 2007 6:32 am
by DoubleDutch
In windows you just:
(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?
Posted: Tue Jan 02, 2007 10:30 am
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
Posted: Tue Jan 02, 2007 1:36 pm
by DoubleDutch
Thanks for the help, but it didn't work on 'Kubuntu'.

Posted: Tue Jan 02, 2007 2:19 pm
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", "")
Posted: Tue Jan 02, 2007 2:33 pm
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...
Posted: Tue Jan 02, 2007 2:43 pm
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
==>
http://portland.freedesktop.org/wiki/
Posted: Tue Jan 02, 2007 2:49 pm
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.
Posted: Tue Jan 02, 2007 3:04 pm
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

).