#!/bin/bash

if [ "$(uname)" == 'Darwin' ]; then
	OS='Mac'
else
	echo "Your platform ($(uname -a)) is not supported."
	exit 1
fi

if ps x | grep "Dropshare 4.app" | grep -v "grep" > /dev/null; then
	APP_NAME="Dropshare 4.app"
	if [ -x "/Applications/$APP_NAME" ]; then
		APP_PATH="/Applications"
	elif [ -x "$HOME/Applications/$APP_NAME" ]; then
		APP_PATH="$HOME/Applications"
	else
		APP_PATH="$(mdfind "kMDItemCFBundleIdentifier == 'net.mkswap.Dropshare4'" | head -1 | xargs -0 dirname)"
	fi

	if [ ! -x "$APP_PATH/$APP_NAME" ]; then
        echo "Cannot locate Dropshare 4.app, please install Dropshare 4.app to use this script."
        exit 1
	fi

    if [ $# -eq 0 ]
        then
            echo "Usage: ds <filename>"
            exit 1
    fi
	open -a "$APP_PATH/$APP_NAME" "$@"
else
	echo "Dropshare 4.app is not running, please launch the application before using this script."
fi
