#!/bin/sh
# Client ships inside the addon. macOS system tools only; no Node/npm/Python.
client_path=$0
while [ -L "$client_path" ]; do
  link=$(/usr/bin/readlink "$client_path")
  case "$link" in /*) client_path=$link;; *) client_path="$(dirname -- "$client_path")/$link";; esac
done
client_dir=$(CDPATH= cd -- "$(dirname -- "$client_path")" && pwd)
reply=$(/usr/bin/osascript -l JavaScript "$client_dir/client.jxa" "$@")
status=$?
printf '%s\n' "$reply"
[ "$status" -eq 0 ] || exit "$status"
case "$reply" in '{"ok":false,'*) exit 1;; esac
