#!/bin/sh

SCRIPT_DIR=$(dirname "$0")
SCRIPT=$"Diff Unsaved Changes in Kaleidoscope.sh"
APP_SUPPORT=$"$HOME/Library/Application Support/BBEdit/Scripts"
ALT_APP_SUPPORT=$"$HOME/Library/Containers/com.barebones.bbedit/Data/Library/Application Support/BBEdit/Scripts"
TOOL_ENDPATH="$APP_SUPPORT/$SCRIPT"
ALT_TOOL_ENDPATH="$ALT_APP_SUPPORT/$SCRIPT"

TOOL_SRCPATH="$SCRIPT_DIR/$SCRIPT"

if [ -r "$TOOL_SRCPATH" ] ; then
	echo "Source found $TOOL_SRCPATH"
	if [ -r "$APP_SUPPORT" ] ; then
		echo "Found regular scripts folder in $APP_SUPPORT"
		# Copy integration script to application support
		cp "$TOOL_SRCPATH" "$TOOL_ENDPATH" || { echo "Copy to '$TOOL_ENDPATH' failed"; exit 1; }
	else
		echo "Found alternative scripts folder in $ALT_APP_SUPPORT"
		cp "$TOOL_SRCPATH" "$ALT_TOOL_ENDPATH" || { echo "Copy to '$ALT_TOOL_ENDPATH' failed"; exit 1; }
	fi
else
	echo "Could not read integration script source '$TOOL_SRCPATH'" >&2
	exit 1
fi

exit 0
