-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr.sh
More file actions
executable file
·36 lines (27 loc) · 849 Bytes
/
ocr.sh
File metadata and controls
executable file
·36 lines (27 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
CREDIT="Taz"
tmp="/tmp/ocr-$(date +%s).png"
if ! command -v maim >/dev/null 2>&1; then
notify-send "OCR Error" "maim not installed"
exit 1
fi
if ! command -v tesseract >/dev/null 2>&1; then
notify-send "OCR Error" "tesseract not installed"
exit 1
fi
maim -s "$tmp" 2>/dev/null
if [ ! -f "$tmp" ] || [ ! -s "$tmp" ]; then
notify-send "OCR" "Screenshot canceled"
rm -f "$tmp"
exit 1
fi
langs=$(tesseract --list-langs 2>&1 | tail -n +2 | tr '\n' '+' | sed 's/+$//')
[ -z "$langs" ] && langs="eng"
text=$(tesseract "$tmp" stdout -l "$langs" 2>/dev/null | sed '/^$/d' | tr '\n' ' ' | xargs)
if [ -n "$text" ]; then
echo -n "$text" | xclip -selection clipboard
notify-send "OCR by $CREDIT" "✓ Text copied to clipboard"
else
notify-send "OCR by $CREDIT" "✗ No text detected"
fi
rm -f "$tmp"