Files
community-plugins/screen-toolkit/scripts/lens-upload.sh
T
636317303c screen-toolkit : full screen utility (#221)
* screen-toolkit: add Noctalia v5 plugin

* screen-toolkit: credit original plugin

* screen-toolkit: fix recording, OCR capture, and result panel UX

* screen-toolkit: rename record tool labels to Record / Rec FS

* screen-toolkit: update plugin thumbnail

* screen-toolkit: fix README validation (backtick deps, result panel toggle)

* screen-toolkit: fix OCR results and dependencies

* screen-toolkit: backtick recording and annotator deps in README

---------

Co-authored-by: Ahmed5Emad <ahmed5emad@users.noreply.github.com>
2026-08-03 08:22:08 -04:00

38 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Args: $1=gx $2=gy $3=gw $4=gh
# Captures a region and opens it in Google Lens via a temporary upload.
# Exit 1 — missing dependency (dep name written to stdout)
# Exit 2 — capture failed
# Exit 3 — upload failed
GX="$1"; GY="$2"; GW="$3"; GH="$4"
FILE="/tmp/screen-toolkit-lens.png"
GRIM_CURSOR_ARGS=()
[ "${SCREEN_TOOLKIT_CAPTURE_CURSOR:-0}" = "1" ] && GRIM_CURSOR_ARGS+=(-c)
for dep in grim curl jq xdg-open; do
command -v "$dep" >/dev/null 2>&1 || { echo "$dep"; exit 1; }
done
sleep 0.15
# Capture the requested region. Without this the upload would send whatever
# stale image happens to be left at $FILE (or nothing at all).
grim "${GRIM_CURSOR_ARGS[@]}" -g "${GX},${GY} ${GW}x${GH}" "$FILE" 2>/dev/null \
|| { echo "ERROR: grim capture failed" >&2; exit 2; }
RESP=$(curl -sS -f -A 'Mozilla/5.0' --connect-timeout 20 --max-time 60 \
-F "files[]=@$FILE" 'https://uguu.se/upload' 2>/dev/null) || \
RESP=$(curl -sS -A 'Mozilla/5.0' --connect-timeout 20 --max-time 60 \
-F "files[]=@$FILE" 'https://uguu.se/upload.php' 2>/dev/null)
rm -f "$FILE"
URL=$(printf '%s' "$RESP" | jq -r '.files[0].url // empty' 2>/dev/null)
if [ -n "$URL" ] && [[ "$URL" == http* ]]; then
xdg-open "https://lens.google.com/uploadbyurl?url=$URL" >/dev/null 2>&1 &
else
exit 3
fi