#!/usr/local/bin/tclsh
global env

set urlspec [lindex $argv 0]

if {$urlspec==""} {
	puts stdout "Usage: $argv0 urlspec"
	exit 1
}

#
#	Look for a running netscape
#
catch "exec ps x | grep -i netscape | grep -v grep" res
set netscapepid [lindex $res 0]
regsub -all {[^0-9]} $netscapepid {} netscapepid
if {"x$netscapepid"!="x"} {
	if {[file executable /usr/local/bin/netscape]} {
		if {![catch "exec /usr/local/bin/netscape -remote OpenURL($urlspec)" res]} { exit 0 }
	}
}

#
#	Find a browser that can be started up to view the file
#
if {![file executable /usr/local/bin/netscape]} {
	puts stdout "Netscape browser could not be found in /usr/local/bin"
	exit 1
}

#set cmd "(/usr/local/bin/netscape -install $urlspec) </dev/null >/dev/null 2>/dev/null &"

#regsub -all {#} $cmd {\\#} cmd
if {[catch "exec /usr/local/bin/netscape -install $urlspec" res]} {
	puts stdout "Could not launch netscape to view $urlspec"
	puts stdout "Result=$res"
	exit 1
}

exit 0
