#!/bin/bash # Select a screen region, OCR it (English + Russian) and put the text in the clipboard. if ! command -v tesseract >/dev/null; then notify-send -a ocr "OCR" "tesseract is not installed:\nsudo dnf install tesseract tesseract-langpack-eng tesseract-langpack-rus" exit 1 fi geom=$(slurp -b 00000066 -c e91e63ff -w 2) || exit 0 img() { grim -g "$geom" -; } if command -v magick >/dev/null; then img() { grim -g "$geom" - | magick png:- -resize 200% -colorspace Gray png:-; }; fi text=$(img | tesseract stdin stdout -l eng+rus --psm 6 2>/dev/null | sed 's/[[:space:]]*$//') [ -z "$text" ] && { notify-send -a ocr "OCR" "nothing recognised"; exit 1; } printf '%s' "$text" | wl-copy notify-send -a ocr "Copied $(printf '%s\n' "$text" | wc -l) line(s)" "$(printf '%s\n' "$text" | head -2)"