-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.sh
executable file
·30 lines (22 loc) · 905 Bytes
/
screen.sh
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
#!/bin/sh
if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi
source ./env-vars
# The above commands exports OCR_API_KEY=xxxxxxxxxxxx defined in the env-vars file as
# export OCR_API_KEY=YourAPIKeyGoesHere
FOLDER=$(defaults read com.apple.screencapture location)
SCREENSHOT=${FOLDER}"$1"
OCR_API_URL="https://api.ocr.space/Parse/Image"
SCREENTEXT=${SCREENSHOT}".json"
OCR_WEB_SVR="http://www.ocrwebservice.com/restservices/processDocument?language=english&pagerange=all&tobw=true&gettext=true&outputformat=txt"
curl --silent --connect-timeout 5 --form "file=@${SCREENSHOT}" --form "apikey=${OCR_API_KEY}" ${OCR_API_URL} | /usr/local/bin/jq --ascii-output --join-output '.["ParsedResults"]?|.[0]?|.["ParsedText"]?' > ${SCREENTEXT}
size=$(ls -l "${SCREENTEXT}" | cut -d' ' -f 8)
if [ "$size" -gt 0 ]; then
echo "Success"
exit 1
fi
rm -f ${SCREENTEXT}
echo "Error"
exit 0