Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to open browser window on MacOSX with a given URL and continue execution of the script; script is cross-platform so it should detect whether it's working on MacOSX; it should work on any box with MacOSX (i.e. it should use browser available everywhere, and starting the way it's expected to work everywhere on any version of MacOSX). Could you please suggest how to achieve this? I guess it's system("something1 $url & >/dev/null 2>&1") if $^O =~ /something2/i; Could you please tell what values of "something1" and "something2" are. Thanks.

Replies are listed 'Best First'.
Re: how to open browser window with given URL on MacOSX?
by adrianh (Chancellor) on Apr 22, 2004 at 10:42 UTC

    Doing:

    if ($^O eq 'darwin' ) { system( open => $url ) == 0 or die "could not open $url"; };

    Should work if the user hasn't misconfigured their box.

      And just to elaborate, open will also do basically what double-clicking on any item in the Finder would do (open it in the default application, or open a directory in a Finder window). There's also an open source app called launch which can do similar things as well as ask apps to print documents.

      Not that that's got anything to do with perl . . . :)

      That may work on a Mac but not on Win32 for some reason. I'm getting the message:

      MSWin32'open' is not recognized as an internal or external command, op +erable program or batch file.

      Using an exec does open the browser, but the program closes after it hits the exec. Any other ideas on how to do this under Win32 without having to use HTML::DIsplay?

      Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
        That may work on a Mac but not on Win32 for some reason

        The $^O eq 'darwin' should have given that away :-). It's a Max OS X specific binary.

Re: how to open browser window with given URL on MacOSX?
by PodMaster (Abbot) on Apr 22, 2004 at 13:37 UTC
    you know, a very short time ago some AM asked how to do this on windows, juse HTML::Display.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      you know, a very short time ago some AM asked how to do this on windows, juse HTML::Display

      Is there a way of getting HTML::Display to open a URL directly - I thought it only displayed HTML supplied from Perl?