img2text-to-clipboard.sh 390 B

1234567891011121314151617
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. img="/tmp/${0##*/}.png"
  4. xclip -selection clipboard -t image/png -o > "$img"
  5. # Convert the image to text using Tesseract OCR
  6. text=$(tesseract "$img" -)
  7. # text=$(tesseract -l eng "$img" -)
  8. # get rid of ^L lines
  9. lines=$(printf "%s" "$text" | wc -l)
  10. # # Copy the text to clipboard
  11. echo "$text" | head -n "$lines" | xclip -sel clip