#!/bin/bash
scrot-ocr: Select screen region → OCR → clipboard
Deps: grim, slurp, tesseract, wl-clipboard, libnotify
set -euo pipefail

LANG="${1:-eng}"
IMG="/tmp/scrot-ocr-$(date +%s).png"

grim -g "$(slurp -d)" "$IMG"
TEXT=$(tesseract "$IMG" stdout -l "$LANG" 2>/dev/null | sed '/^[[:space:]]*$/d')

echo -n "$TEXT" | wl-copy --paste-once
echo "$TEXT"

notify-send "scrot-ocr" "$(echo "$TEXT" | wc -l) lines copied to clipboard" -t 3000
rm -f "$IMG"
