37 lines
850 B
Bash
Executable File
37 lines
850 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This script allows the user to make a selection, then runs that selection through OCR and copies the result to clipboard
|
|
|
|
case "$XDG_SESSION_TYPE" in
|
|
"wayland")
|
|
copy="wl-copy"
|
|
screenshot="grim -g"
|
|
slop=$(slurp -f "%x,%y %wx%h") || exit 1
|
|
;;
|
|
"x11")
|
|
copy="xclip -selection c"
|
|
screenshot="import -window root -crop "
|
|
slop=$(slop -f "%G") || exit 1
|
|
;;
|
|
*)
|
|
dunstify -t 2000 -u low -i ~/.icons/candy-icons/apps/scalable/code.svg "Current session type not supported by tess.sh"
|
|
exit
|
|
;;
|
|
esac
|
|
|
|
# files
|
|
imagefile="/tmp/tesseract.$RANDOM.png"
|
|
text="/tmp/translation"
|
|
|
|
# get screenshot
|
|
read -r G <<< "$slop"
|
|
bash -c "$screenshot \"$G\" $imagefile"
|
|
|
|
# OCR, save to clipboard
|
|
tesseract $imagefile $text 2>/dev/null
|
|
cat "$text.txt" | bash -c "$copy"
|
|
|
|
# cleanup
|
|
rm $text".txt"
|
|
rm "$imagefile"
|