added ocr screenshot
This commit is contained in:
@@ -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+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+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+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
|
-- Audio Control
|
||||||
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ 0; wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+"))
|
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ 0; wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+"))
|
||||||
|
|||||||
Executable
+38
@@ -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
|
||||||
Reference in New Issue
Block a user