Skip to content

Instantly share code, notes, and snippets.

@tianchentong
Forked from pnc/ocr-shot.sh
Created March 13, 2020 13:30
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 tianchentong/6c017a80abfe347a6a033fec6dd6aaf4 to your computer and use it in GitHub Desktop.
Save tianchentong/6c017a80abfe347a6a033fec6dd6aaf4 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/tessdata/ "$1" stdout -l eng | 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" "$1"
mdimport "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment