Skip to content

Commit

Permalink
Make maimpick OCR to work with languages other than English.
Browse files Browse the repository at this point in the history
  • Loading branch information
forgoty committed Aug 3, 2024
1 parent 628ed4d commit 2cd47e9
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .local/bin/maimpick
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@
# highlighting an area to copy. scrotcucks on suicidewatch right now.

# variables
opts="a selected area
current window
full screen
a selected area (copy)
current window (copy)
full screen (copy)
copy selected image to text
copy selected image to text (choose language)"
output="$(date '+%y%m%d-%H%M-%S').png"
xclip_cmd="xclip -sel clip -t image/png"
ocr_cmd="xclip -sel clip"
xclip_cmd_png="xclip -sel clip -t image/png"
xclip_cmd_text="xclip -sel clip"
tesseract_langs="$(tesseract --list-langs 2>/dev/null | sed '1d;/^List/d;/osd/d')"

case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)\\ncopy selected image to text" | dmenu -l 7 -i -p "Screenshot which area?")" in
"a selected area") maim -u -s pic-selected-"${output}" ;;
"current window") maim -B -q -d 0.2 -i "$(xdotool getactivewindow)" pic-window-"${output}" ;;
"full screen") maim -q -d 0.2 pic-full-"${output}" ;;
"a selected area (copy)") maim -u -s | ${xclip_cmd} ;;
"current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;;
"full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;;
"copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && maim -u -s > "$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" ;;
opt="$(printf "%s\n" "${opts}" | dmenu -l 7 -i -p "Screenshot which area?")"
case "${opt}" in
"a selected area") maim -u -s pic-selected-"${output}" ;;
"current window") maim -B -q -d 0.2 -i "$(xdotool getactivewindow)" pic-window-"${output}" ;;
"full screen") maim -q -d 0.2 pic-full-"${output}" ;;
"a selected area (copy)") maim -u -s | ${xclip_cmd_png} ;;
"current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd_png} ;;
"full screen (copy)") maim -q -d 0.2 | ${xclip_cmd_png} ;;
"copy selected image to text") maim -u -s | tesseract stdin stdout -l eng | ${xclip_cmd_text} ;;
"copy selected image to text (choose language)") lang="$(printf "%s" "$tesseract_langs" | dmenu -i -p "Choose Language")"
maim -u -s | tesseract stdin stdout -l $lang | ${xclip_cmd_text} ;;
esac

0 comments on commit 2cd47e9

Please sign in to comment.