#!/bin/bash

result=`pgrep quartz`
#echo $result
if [ "$result" == "" ] ; then
  echo "Starting XQuartz"
  open /Applications/Utilities/XQuartz.app
  sleep 4s
fi
# delete old EyeSim process
result=`pgrep EyeSim`
#echo $result
if [ "$result" != "" ] ; then
  kill "$result"
fi
sleep 1s

if [ "$#" -eq 1 ]; then
  open /Applications/EyeSim.app --args $PWD/$1
else
  open /Applications/EyeSim.app
fi
