Skip to content

Instantly share code, notes, and snippets.

@j4velin
Last active January 20, 2022 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j4velin/1fd7fdf6c111c7c39e7ec13f68fc7678 to your computer and use it in GitHub Desktop.
Save j4velin/1fd7fdf6c111c7c39e7ec13f68fc7678 to your computer and use it in GitHub Desktop.
Script to run ocrmypdf on new pdf files and move the ocr'ed version to the paperless input directory
#/bin/bash
workdir=/home/pi/ocr.work
scaninput=/home/pi/scaninput
outdir=/home/pi/paperless.consume
inotifywait -m -e close_write -e moved_to $scaninput |
while read -r path action file; do
echo "Waiting for $file..."
sleep 10
echo "Processing $file..."
out="${file%%.*}.pdf"
ocrmypdf -l eng+deu "$scaninput/$file" "$workdir/$out" 2>&1 | tee /tmp/paperless.ocr.log
echo "File $file processed"
mv -n "$workdir/$out" "$outdir/$out" && rm "$path/$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment