cliscript

Easy way to OCR in my Arch

1 min read
0 views






This is a quick OCR hotkey — press Super+Shift+O → select any text on screen → the text is automatically copied to your clipboard (ready to paste).

It's a very common lightweight setup in Hyprland/Sway setups for copying text from images, videos, PDFs, or anything that isn't selectable normally.

keybind.conf
 bind = $mainMod+Shift, O, exec, grim -g "$(slurp)" /tmp/ocr.png && tesseract -l eng /tmp/ocr.png - | wl-copy && rm /tmp/ocr.png

Action (when you press that hotkey):

  1. grim -g "$(slurp)" /tmp/ocr.png
    • slurp lets you select a region on the screen with your mouse (it shows a crosshair/selection box).
    • grim takes a screenshot of exactly that selected region and saves it temporarily as /tmp/ocr.png.
  2. tesseract -l eng /tmp/ocr.png -
    • Runs Tesseract OCR (Optical Character Recognition) on the screenshot.
    • -l eng → uses the English language model.
    • The final - tells tesseract to output the recognized text to stdout (instead of a file).
  3. | wl-copy
    • Pipes the extracted text directly into wl-copy, which copies it to your Wayland clipboard.
    • After this, you can paste the text anywhere (Ctrl+V) as if you had typed it.
  4. && rm /tmp/ocr.png
    • Cleans up by deleting the temporary screenshot file.
0
Back to notes