38 lines
1.2 KiB
Bash
Executable File
38 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
###
|
|
### ~/.config/hypr/scripts/screenshot/ocr_area.sh
|
|
###
|
|
|
|
# Ensure dependencies exist
|
|
for cmd in slurp grim tesseract wl-copy; do
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
notify-send -a "OCR" -u critical "OCR Error" "Missing required command: $cmd"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Select a region with slurp; exit silently if cancelled (ESC/right-click)
|
|
geometry=$(slurp) || exit 0
|
|
|
|
# Capture region directly from grim, pipe into tesseract, and save stdout to clipboard
|
|
text=$(grim -g "$geometry" - | tesseract - stdout --psm 6 2>/dev/null)
|
|
|
|
# Exit if no text was detected
|
|
if [ -z "$text" ]; then
|
|
if command -v notify-send >/dev/null 2>&1; then
|
|
notify-send -a "OCR" -i edit-select-all "OCR Failed" "No text recognized in selected area."
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Copy detected text to Wayland clipboard
|
|
printf "%s" "$text" | wl-copy
|
|
|
|
# Notify user of successful extraction
|
|
if command -v notify-send >/dev/null 2>&1; then
|
|
# Truncate text preview for notification brevity
|
|
preview=$(echo "$text" | head -n 3)
|
|
notify-send --app-name "Screenshot" --icon "edit-find" -u normal "OCR" "Text Copied to Clipboard:\n$preview"
|
|
fi
|
|
|
|
# Install: sudo pacman -S grim slurp tesseract tesseract-data-eng wl-clipboard libnotify |