Created
July 20, 2024 20:07
-
-
Save CapMousse/454ec041880e78b4e3a894e7a4033faa to your computer and use it in GitHub Desktop.
Screenshot OCR for text extraction on Hyprland
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dependencies: tesseract-ocr imagemagick wl-clipboard hyprshot | |
die(){ | |
notify-send "$1" | |
exit 1 | |
} | |
cleanup(){ | |
[[ -n $1 ]] && rm -r "$1" | |
} | |
SCR_IMG=$(mktemp -d) || die "failed to create tmpdir" | |
# shellcheck disable=SC2064 | |
trap "cleanup '$SCR_IMG'" EXIT | |
hyprshot -m region -f scr.png --silent -o $SCR_IMG || die "failed to take screenshot" | |
mogrify -modulate 100,0 -resize 400% "$SCR_IMG/scr.png" || die "failed to convert image" | |
tesseract "$SCR_IMG/scr.png" "$SCR_IMG/scr" &> /dev/null || die "failed to extract text" | |
wl-copy < "$SCR_IMG/scr.txt" || die "failed to copy text to clipboard" | |
notify-send "Text extracted from image" || die "failed to send notification" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment