[Lazarus] Open URL in "default" browser X-platform

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Thu Dec 4 12:12:10 CET 2008


Bart wrote:
> Hi,
> 
> I come from Windows/Delphi (3.0) background and I'm gradually moving
> towards Lazarus/fpc.
> 
> Opening an URL in Windows is a piece of cake, you just let the OS take
> care of the assotiations with the http protocol to open it (using
> shellexecute).
> This of course will not do for other platforms.
> 
> So I set myself the task of launching an URL in an external browser on
> other platforms.
> Since I only have Linux (besides Win) I began with that.
> 
> I tried to find examples on the net, but had no luck.
> I might well be re-inventing the wheel though...
> 
> Here's my approach:
> 
> - try to detect the windowmanger (for now I know how to do this for
> KDE and GNOME, XFCE is on my whishlist)
> 
> On KDE
> - lookup DESKTOK_LAUNCH environment variable
> - if not there, look for kde-open
> - if not there look for kfmclient
> - if not there look for xdg-open
> - if not there try fallback
> (possibly using gnome-open might also work under KDE ???)
> 
> On GNOME
> - look fo gnome-open
> - if not there, look for xdg-open
> - if not there try fallback
> 
> Fallback
> - search for know browsers (firefox, iceweasel, mozilla, opera,
> konqueror, ...(suggestions are welcome))
> 
> If browser (or URL handler like kde-open, xdg-open etc.) is found
> launch it with the appropriate URL.
> 
> This approach (the finding mechanism) seems to work at least on my
> Suse KDE desktop.
> 
> I would like your opinions on this approach, and better still, I would
> like some suggestions how to achieve something similar on a Mac.
> (I suppose on Mac OSX the linux approach should work also???)
> 
> And as a final rather dumb question: do all supported OS's have an
> environmentvariable PATH (as this is used in the fallback mechanism)?

There's already a standard for that: xdg-open. Granted that a fallback 
for older distreaux that don't include it is useful, but apart from that 
rather than trying to reinvent the wheel your time would be better spent 
cooperating with the people who've implemented it- I'm sure they'd 
appreciate your help.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the Lazarus mailing list