1. Runs the cli program "ocrmypdf" on the file
2. Outputs the resulting OCR'd file to a different directory
3. Tags the resulting file with another cli program, "tag"
Here is the embedded script (run from ZSH):
- Code: Select all
PATH=$PATH:/opt/homebrew/bin
export PATH
filename=$(basename "$1")
filename=${filename%.*}
converting_directory=~/Documents/processed/
converting_filename="$filename.pdf"
if ocrmypdf --clean --rotate-pages "$1" "$converting_directory""$converting_filename"
then
tag -a "pdf/a,scan" "$converting_directory""$converting_filename"
rm $1
echo "OCR succeeded"
else
echo "OCR failed"
fi
When I run this script on a PDF outside of Hazel, it works. However, now when triggered via Hazel it looks like it's failing on the "ocrmypdf" command. The logs show that matching happens as expected, and the script definitely gets called but the OCR step fails.
This is the relevant bit from the logs
- Code: Select all
2024-01-07 17:01:24.037 hazelworker[49612] DEBUG: About to process directory /Users/sam/Documents/inbox/hazel-scan-ocr
2024-01-07 17:01:24.042 hazelworker[49612] 20240107_151957.pdf: Rule Process Scans matched.
2024-01-07 17:01:24.042 hazelworker[49612] DEBUG: New rule signature. Executing actions.
Old signatures: (
)
New Signature:{dateAdded >[cd] dateMatched}:{(shellscript:/opt/homebrew/bin/zsh:0012fb12ac317454ed0977ff22fc908e,{
})}
2024-01-07 17:01:24.426 hazelworker[49612] DEBUG: == script output ==
1 [tesseract] Leptonica Error in fopenReadStream: file not found: 000001_rasterize_preview.jpg
1 [tesseract] Leptonica Error in findFileFormat: image file not found: /tmp/ocrmypdf.io.mvzd3qav/000001_rasterize_preview.jpg
1 [tesseract] Leptonica Error in fopenReadStream: file not found:
1 [tesseract] Leptonica Error in pixRead: image file not found:
1 [tesseract] Image file cannot be read!
1 [tesseract] Error during processing.
SubprocessOutputError
OCR failed
== End script output ==
It looks like the ocrmypdf program isn't finding the source file, but I'm not sure what the problem is or why it was working previously but stopped. Hoping someone with more scripting knowledge can point me in the right direction.
OS X Version 13.6.3 (Build 22G436)
Hazel Version 5.3.1 (Build 2371)