#!/bin/sh
_SCRIPT_NAME=mail
_SCRIPT_LOCATION=~/bin
#v  mail by duus
#i  no installation information at this time
#h  mail by duus
if [ "$1" = "" ]
	then
	echo "open mail"
	open /Applications/Mail.app &
fi
for arg in "$@"
	do
	_command=""
	#############################         commands
		if [ "$arg" = "c" -o "$arg" = "check" ]
			then
#h
#h  _std commands_
#h    (c)heck> will check for new mail
			_command="check for new mail"
			echo "${_command}"
#h
#h _Application Control_
		elif [ "$arg" = "hide"  ]
			then
#h    <hide> hides mail
		echo "hide mail"
echo | osascript <<EOF
   tell application "System Events"
   	set visible of process "Mail" to false
   end tell
EOF
			_command="no_command"
		elif [ "$arg" = "open" -o "$arg" = "start" ]
			then
#h    <open>/<start> starts Mail
			echo "start mail"
			_command="activate"
		elif [ "$arg" = "quit" ]
			then 
#h    <quit> will quit mail
			_command="quit"
			echo "quit mail"
################################################# information commands
#h 
#h _mail cli information_		
		elif [ "$arg" = "i" -o "$arg" = "install" ]
			then
#h    <(i)nstall> displays install information
			grep "^#i" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			_command="no_command"
		elif [ "$arg" = "v" -o "$arg" = "version" ]
			then
#h    <(v)ersion> displays version information
			grep "^#v" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			_command="no_command"
		elif [ "$arg" = "h" -o "$arg" = "help" ]
			then
#h    <(h)elp> displays this help file
			grep "^#h" $_SCRIPT_LOCATION/${_SCRIPT_NAME} | more
			_command="no_command"
		elif [ "$arg" = "src" -o "$arg" = "source" -o "$arg" = "code" ]
			then
#h    <src> displays the source code
			more $_SCRIPT_LOCATION/${_SCRIPT_NAME}
			_command="no_command"
		else
			echo "error: mail $arg not understood ($*)"
		fi
	#
	# run command
	#
#######################################  EXECUTE COMMAND
	if [  "${_command}" != "no_command" ]
		then
echo | osascript <<EOF
tell application "Mail"
	$_command
end tell
EOF
	fi
	#
done
#h



