#!/bin/sh
# This is a script to run the netscape program in "remote control"
# mode, for instance as a URL viewer for ml. It's purpose is to
# search for a "netscape" process running on the current machine,
# under your username, and if found, send it a command to load
# a new URL. If no such process is running, it start one. This avoids
# having several netscape processes running at once. It is used by
# putting "remotescape '%s' &" as the URL command under "More Preferences"
# in the ML option menu; and using the "Follow Web Link" command in
# the read window. 
# Note that this program can also invoke "lynx", (a text based browser),
# if 'X' isn't running, but that isn't really applicable to ML use.



if [ $1 ] ; then

	MYNAME=`whoami`

	if [ $DISPLAY ] ; then
		MPID=`ps -auxww | grep $MYNAME | grep netscape | \
		grep -v grep | awk '{print $2}'` > /dev/null 2>&1
		if [ $MPID ] ; then
			netscape -remote "openURL($1)"
			exit 0
		else
			exec netscape $1 &
		fi
	else
		exec lynx $1
	fi

else
	echo "Usage: remotescape URL"
	exit 0
fi
