ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Morten S. Mortensen" <morten.morten...@tietoenator.com>
Subject Invoking the default browser of any OS
Date Sun, 15 Feb 2004 19:46:31 GMT

Hi,

Who can tell how to invoke the default browser of any operating system? -From Ant.

Below I have an Ant-snippet, which can be used with <import> - it is a part of a bigger
setup. I have a test on condition-os-family "Windows" and I have one on "UNIX".

The browse-target for Windows is perfect. But what do I write for UNIX? -Say I want to target
Linux only, what are the possibilities for not wiring specific browser-executables like "mozilla",
"opera" or whatever?

Regards,
Morten Sabroe Mortensen

     -----

<?xml version="1.0" encoding="UTF-8"?>

<!-- *** FILE "browse.xml" ************************************************* -->
<!--
  Build file for Apache Ant.
  Morten Sabroe Mortensen.
-->
<!-- *********************************************************************** -->

<project
  name="Krapyl Utility - Invoke Default User Agent"
  default="util:browse"
>

  <!-- Declare alias: -->
  <target
    name="browse"
    depends="util:browse"
  >
    <!-- Empty! -->
  </target>


  <!--
    Invokes the default user-agent.
    Property "user-agent.browse.url" must contain the URL to show.
  -->
  <target
    name="util:browse"
  >
    <if>
      <os family="windows"/>
      <then>
        <antcall
          target="private:browse_MicrosoftWindows"
        />
      </then>
    </if>

    <if>
      <os family="unix"/>
      <then>
        <antcall
          target="private:browse_GenericUNIX"
        />
      </then>
    </if>

  </target>


  <target
    name="private:browse_MicrosoftWindows"
  >
    <property
      name="user-agent.executable"
      value="rundll32.exe"
    />
    <property
      name="user-agent.executable.arg"
      value="url.dll, FileProtocolHandler"
    />

    <antcall
      target="private:browse_Any"
    />
  </target>


  <target
    name="private:browse_GenericUNIX"
  >
    <property
      name="user-agent.executable"
      value="mozilla"
    />
<!-- NOTE: Wiring "mozilla" is a temporary *HACK*! -->
<!-- TODO: How to invoke the default browser upon generic UNIX! -->
    <property
      name="user-agent.executable.arg"
      value=""
    />

    <antcall
      target="private:browse_Any"
    />
  </target>


  <target
    name="private:browse_Any"
  >
    <exec
      dir="${basedir}"
      executable="${user-agent.executable}"
    >
      <arg line="${user-agent.executable.arg}"/>
      <arg line="${user-agent.browse.url}"/>
    </exec>
  </target>

</project>

<!-- ******** "browse.xml" ************************************************* -->

     -----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message