Skip to content

Instantly share code, notes, and snippets.

@Not-Dhanraj
Created February 19, 2026 21:00
Show Gist options
  • Select an option

  • Save Not-Dhanraj/f81f912db1e81a2a0ebd8d4d613c8f57 to your computer and use it in GitHub Desktop.

Select an option

Save Not-Dhanraj/f81f912db1e81a2a0ebd8d4d613c8f57 to your computer and use it in GitHub Desktop.
A fast, on-device OCR solution for GNOME Wayland

GNOME Wayland OCR Screenshot: Copy Text to Clipboard

A fast, on-device OCR solution for GNOME Wayland - select any area of your screen and get the text copied straight to your clipboard, no intermediate image save required.

Problem

  • You want to copy text from an image, video, or non-selectable UI element
  • You don't want to save a screenshot and manually run OCR on it
  • You want it all triggered by a single keyboard shortcut

Solution

Step 1: Install Dependencies

sudo dnf install -y gnome-screenshot tesseract wl-clipboard

For non-English text, also install the relevant language pack, e.g.:

sudo dnf install -y tesseract-langpack-hin  # Hindi

Step 2: Create the OCR Script

Create the script file:

mkdir -p ~/.local/bin
nano ~/.local/bin/ocr-screenshot.sh

Add this content:

#!/bin/bash
# On-device OCR screenshot - copies recognized text directly to clipboard
# Dependencies: gnome-screenshot, tesseract, wl-clipboard

FILE=$(mktemp /tmp/ocr-screenshot-XXXXXX.png)

gnome-screenshot -af "$FILE" && \
  tesseract "$FILE" stdout --oem 1 -l eng 2>/dev/null | \
  wl-copy

rm -f "$FILE"

Make it executable:

chmod +x ~/.local/bin/ocr-screenshot.sh

Step 3: Add a Keyboard Shortcut

  1. Open SettingsKeyboardView and Customize Shortcuts
  2. Scroll down and click "Add Custom Shortcut"
  3. Fill in:
    • Name: OCR Screenshot
    • Command: /home/YOUR_USERNAME/.local/bin/ocr-screenshot.sh (replace YOUR_USERNAME)
    • Shortcut: Press your desired key combo (e.g., Super + T)

Step 4: Use It!

Press your shortcut, select the area with text, and the recognized text will be:

  • Copied directly to clipboard - ready to paste anywhere
  • No screenshot file saved to disk
  • No image ever touches your clipboard

How It Works

Part What it does
gnome-screenshot -af "$FILE" Takes an area screenshot and saves it to a temp file (no dialog)
tesseract "$FILE" stdout Runs OCR on the image and outputs recognized text to stdout
--oem 1 Uses LSTM engine only - faster and more accurate than legacy mode
-l eng Explicit language selection, skips auto-detection overhead
wl-copy Copies the piped text into the Wayland clipboard
rm -f "$FILE" Cleans up the temp file immediately after

Multi-language Support

Change -l eng to any language or combination:

tesseract "$FILE" stdout --oem 1 -l eng+hin 2>/dev/null | wl-copy

Find available language packs:

dnf search tesseract-langpack

Tested On

  • Fedora 43
  • GNOME 49
  • Wayland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment