Skip to content

Instantly share code, notes, and snippets.

@bion
Last active December 23, 2021 09:20
Show Gist options
  • Save bion/5097ccc61f703f7e74cc77e5c4d08618 to your computer and use it in GitHub Desktop.
Save bion/5097ccc61f703f7e74cc77e5c4d08618 to your computer and use it in GitHub Desktop.
OCR latest screenshot
#! /usr/bin/env bash
set -euf -o pipefail
input_file="$1"
temp_file=$(mktemp)
convert "$input_file" "$temp_file.tif"
tesseract -l eng "$temp_file.tif" "$temp_file" &> /dev/null
cat "$temp_file.txt"
rm "$temp_file"
rm "$temp_file.txt"
rm "$temp_file.tif"
#! /usr/bin/env bash
set -euf -o pipefail
_current_os=$(uname)
function is_linux() {
[[ "$_current_os" == "Linux" ]]
}
if is_linux; then
screenshot_dir=~/Pictures
else
screenshot_dir=~/Desktop
fi
latest="$screenshot_dir/$(ls -Art $screenshot_dir | tail -n 1)"
extract-text "$latest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment