Files
arthur-os/bin/omarchy-capture-text-extraction
Vitalii BondarandGitHub ba1d699c11 Allow configuring OCR languages via OMARCHY_OCR_LANGS (#5623)
Hardcoded -l eng makes SUPER+CTRL+PRINT produce garbage on any
non-ASCII English text. Read the language list from
OMARCHY_OCR_LANGS instead, defaulting to eng for backward
compatibility.
2026-05-07 11:49:44 +02:00

27 lines
774 B
Bash
Executable File

#!/bin/bash
# omarchy:summary=Extract text from a screenshot region with OCR
# omarchy:group=capture
# omarchy:examples=omarchy capture ocr
# Keep hyprpicker alive until after grim captures so the screenshot sees the
# frozen overlay rather than live content shifting during teardown.
cleanup_freeze() {
[[ -n $PID ]] && kill $PID 2>/dev/null
}
trap cleanup_freeze EXIT
hyprpicker -r -z >/dev/null 2>&1 &
PID=$!
sleep .1
SELECTION=$(slurp 2>/dev/null)
[[ -z $SELECTION ]] && exit 0
TEXT=$(grim -g "$SELECTION" - | tesseract stdin stdout --oem 1 --psm 6 -l "${OMARCHY_OCR_LANGS:-eng}" --dpi 300 -c preserve_interword_spaces=1 2>/dev/null) || exit 1
[[ -z $TEXT ]] && exit 1
printf "%s" "$TEXT" | wl-copy
notify-send "󰴑 Copied text from selection to clipboard"