# send message to stderr. exclude >&2 if you dont want it that way.
echo_stderr() {
  printf '%s\n' "$1" >&2
}

# return a code specified by $2 or 1 by default.
fail() {
  echo_stderr "$1"
  exit "${2-1}"
}

only_run_on() {
  # shellcheck disable=SC2312
  if [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "$(echo "$1" | tr '[:upper:]' '[:lower:]')" ]; then
    fail "This script only runs on $1, this machine is running $(uname -s)"
  else
    fail "$(uname -s) is valid..."
  fi
}

check_dependency() {
  if ! builtin command -V "$1" >/dev/null 2>&1
  then
    fail "Missing dependency: can't find $1 in your PATH"
  fi
}

# only_run_on "darwin"
check_dependency "osascript"
