From c7db3bc09dc5a9c341f6da984847c062f53fa528 Mon Sep 17 00:00:00 2001 From: Honney Date: Sun, 16 Aug 2026 22:39:33 +0200 Subject: [PATCH] added ocr screenshot --- config/bind.lua | 1 + scripts/screenshot/screenshot_ocr.sh | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 scripts/screenshot/screenshot_ocr.sh diff --git a/config/bind.lua b/config/bind.lua index e5f2e3a..6beb94b 100644 --- a/config/bind.lua +++ b/config/bind.lua @@ -70,6 +70,7 @@ hl.bind("SUPER+P", hl.dsp.exec_cmd("~/.config/hypr/scripts/screenshot/screenshot hl.bind("SUPER+ALT+P", hl.dsp.exec_cmd("~/.config/hypr/scripts/screenshot/screenshot_monitor.sh")) hl.bind("SUPER+SHIFT+P", hl.dsp.exec_cmd("~/.config/hypr/scripts/screenshot/screenshot_area.sh")) hl.bind("SUPER+SHIFT+S", hl.dsp.exec_cmd("~/.config/hypr/scripts/screenshot/screenshot_area_2.sh")) +hl.bind("SUPER+CTRL+O", hl.dsp.exec_cmd("~/.config/hypr/scripts/screenshot/screenshot_ocr.sh")) -- Audio Control hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ 0; wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+")) diff --git a/scripts/screenshot/screenshot_ocr.sh b/scripts/screenshot/screenshot_ocr.sh new file mode 100755 index 0000000..1d4b9d1 --- /dev/null +++ b/scripts/screenshot/screenshot_ocr.sh @@ -0,0 +1,38 @@ +#!/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 -a "OCR" -i edit-select-all "Text Copied to Clipboard" "$preview" +fi + +# Install: sudo pacman -S grim slurp tesseract tesseract-data-eng wl-clipboard libnotify \ No newline at end of file