Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Last active May 1, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loretoparisi/7a0c84c48552f107f1b0d465a6516b97 to your computer and use it in GitHub Desktop.
Save loretoparisi/7a0c84c48552f107f1b0d465a6516b97 to your computer and use it in GitHub Desktop.
Index and Search Screenshot in macOS Finder via OCR
#!/bin/bash
set -e
for f in "$@"
do
contents=$(/usr/local/bin/tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/ "$f" stdout -l eng | /usr/local/bin/xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>$contents</string>
</plist>
EOF
) | plutil -convert binary1 - -o - | xxd -p | tr -d '\n')
xattr -w -x com.apple.metadata:kMDItemFinderComment "$hex" "$f"
mdimport "$f"
done
@loretoparisi
Copy link
Author

loretoparisi commented May 1, 2018

  • Create a new Automator Task
  • Folder Action is "Search Files where Name Contains "Screenshot"

Credits: someone somewhere on Github posted this script first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment