#!/bin/bash
# $1 = device
# $2 = mount point

# First, brush off any non-optical drives, they are taken care of in "openDrive" script
z=`udevil info $1 | grep "removable mounted" | grep "optical"`
if [ $z == "" ]; then
	exit 0
fi

# the following code is used to strip single-quotes off mount point string
x=`udevil info $1 | grep "is mounted" | awk '{print $NF}'`
if [ $x == 1 ]; then
	y=`echo "$2" | tr -d "'"`
	
	## following was just to echo passed values during testing
	#DIALOG=Xdialog
	#$DIALOG --title "HERE" \
	#       --msgbox "first passed arg is $1,\nValue of X is $x,\nValue of 2 is $y" 0 0	
	###################################################
	
	## this was for tweaking behavior with already-open instance of spacefm,
    ## acted kinda flaky, so went to straight new-window
	#wins=`xwininfo -tree -root | grep spacefm | wc -l`
	#if [ $wins -gt  3 ]; then
	#	spacefm "$y" > /dev/null 2>&1
	#else
	#	spacefm -r "$y" > /dev/null 2>&1
	#fi
	###################################################
	spacefm -w "$y" > /dev/null 2>&1
fi
