-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr
More file actions
executable file
·70 lines (60 loc) · 2.54 KB
/
ocr
File metadata and controls
executable file
·70 lines (60 loc) · 2.54 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: ocr
# Created: unknown, 2020
# Author.: @sdushantha, (Siddharth Dushantha)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Monday, 2024/12/09 - 17:38:37
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 1.0.4.85
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# > https://github.com/sdushantha/bin
# ############################################################################
# HISTORY:
#
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
# shellcheck disable=SC1090,SC2154
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
source "$xSHELL_INIT"
use args
packages=(tesseract maim xclip-cmd)
xrequirements "${packages[@]}" pkill wc notify-send cat
xarg --id -n,--no-compositor --var compositor:false --desc "disable compositor (picom)"
xarg --header "Extract a text from screen/image with OCR"
xarg --footer "required: ${packages[*]}"
xrun --xreject-unknow --xversionrc --xcolors "$@"
TXT_FILE="/tmp/ocr.txt"
IMG_FILE="/tmp/ocr.png"
# kill compositors
[ -n "$compositor" ] && {
echo "killing compositors:"
echo -n " '-> picom"; pkill picom; echo " ....[done]"
echo -n " '-> compton"; pkill compton; echo " ..[done]"
}
# Take screenshot by selecting the area
if ! maim -s "$IMG_FILE"; then
# If the user pressed the escape key or did something to terminate the proccess
# taking a screenshot, then just exit
echo "quit" && exit 1
fi
# Do the magic (∩^o^)⊃━☆゚.*・。゚
# Notice how I have removing the extension .txt from the file path. This is
# because tesseract adds .txt to the given file path anyways. So if we were to
# specify /tmp/ocr.txt as the file path, tesseract would out the text to
# /tmp/ocr.txt.txt
tesseract "$IMG_FILE" "${TXT_FILE//\.txt/}"
# Check if the text was detected by checking number
# of lines in the file
LINES=$(wc -l < $TXT_FILE)
if [ "$LINES" -eq 0 ]; then
notify-send "ocr" "no text was detected"
exit 1
fi
# Copy text to clipboard
xclip-cmd --silent < $TXT_FILE
# Send a notification with the text that was grabbed using OCR
notify-send "ocr" "$(cat $TXT_FILE)"