Skip to content

Instantly share code, notes, and snippets.

@alex-rusakevich
Last active May 2, 2025 13:08
Show Gist options
  • Save alex-rusakevich/855d6e0024a97d0bfc01b43c866fe001 to your computer and use it in GitHub Desktop.
Save alex-rusakevich/855d6e0024a97d0bfc01b43c866fe001 to your computer and use it in GitHub Desktop.
Select region on screen and copy text within it to clipboard (GNOME) / Выбрать регион на экране и скопировать текст с него в буфер обмена (GNOME)

English

Place the script at ~/.local/share/bin, run chmod +x on it and create a keyboard shortcut which runs the script (I personally use Win+T).

Installing dependencies on Debian:

sudo apt install gnome-screenshot tesseract-ocr # tesseract-ocr-eng tesseract-ocr-rus etc.

Русский

Поместите скрипт в ~/.local/share/bin, запустите chmod +x путь_к_файлуи задайте в настройках комбинацию клавиш, что будет вызывать скрипт. (я лично использую Win+T)

Как установить зависимости на Debian:

sudo apt install gnome-screenshot tesseract-ocr # tesseract-ocr-eng tesseract-ocr-rus etc.

P.S. В notify-send строку можно поменять, например, на "Готово. Результат анализа скопирован в буфер обмена"

#!/bin/bash
# Define a temporary directory
TMP_DIR=$(mktemp -d)
echo Saving to $TMP_DIR
# Take a screenshot of the selected area and save it as temp.png in the temporary directory
gnome-screenshot -a -f "$TMP_DIR/temp.png"
# Extract text from the screenshot using Tesseract and save it as temp.txt in the temporary directory
tesseract "$TMP_DIR/temp.png" "$TMP_DIR/temp" -l eng+rus
# Open the extracted text file with the default text editor
cat "$TMP_DIR/temp.txt" | python3 -c "import sys; print(sys.stdin.read().strip(), end='')" | xclip -sel clip
notify-send --hint int:transient:1 "Done. The text has been copied to clipboard"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment