#!/bin/bash
cocoadialog='/usr/local/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog'
cd ~/Desktop
cd VisiCutMaterialDb
echo "Checking Camera..."
if ./snap > /dev/null
then
	echo "Nothing" > /dev/null
else
	$cocoadialog msgbox --icon x --informative-text "Please make sure that the camera is plugged in via USB (short cable) and no other application is occupying it" --text "Camera doesn't work" --button1 OK
	exit
fi
cd ../
{
cd VisiCutMaterialDb
while :
do
	sleep 1
	if ./snap > /dev/null
	then
		echo "nothing" > /dev/null
	else
		$cocoadialog msgbox --text "Error refreshing Webcam." --informative-text "The webcam seems to have disconnected. Ther refresh service will be stopped" --button1 OK
		exit
	fi
done
}&
PID=$!
echo "PID is $PID"
$cocoadialog bubble --title "VisiCut ZingCAM" --text "Found Camera.Starting VisiCut and waiting until it is finished"&
open -W VisiCut.app
$cocoadialog bubble --title "VisiCut ZingCAM" --text "VisiCut has stopped.Exiting..."&
echo "killing $PID"
kill $PID
