open a file in the default web browser

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

open a file in the default web browser

Post by cormullion »

I've written this for running on MacOS X:

Code: Select all

(if (= ostype "OSX") 
    (exec (string "open " file ".html")))
which displays the file.html file in the default web browser. Is there an equivalent form for other Unixes, or is 'open' standard?

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Under unix/linux you dont have bindings to a file extention on OS basis,
though some window managers like XFCE, KDE or GNOME can do that its this,
but because of a newlisp execute it wont work, i think...
(i dont use eighter of them so i cant test it..)

You have to explicit execute the webbrowser the user is using for this...

Under windows you might have more luck because that can bind to file
extentions, but also there..its executed from within newlisp so i dot know
the outcome...
-- (define? (Cornflakes))

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

newdep wrote: Under windows you might have more luck because that can bind to file
extentions, but also there..its executed from within newlisp so i dot know
the outcome...
In windows, you associate file extensions with an application to enable launching the application and opening the file by double clicking the file name. I think when you install the OS that it has default association of .html and .htm to Internet Explorer. However, the user can change it to any other application, or even remove any associations. If removed, when the file is double clicked, a dialog opens rather than an application launching.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

Locked