An intelligent bridge between Hazel and DEVONthink Pro for automated document OCR processing.
SmartOCR is an AppleScript that automates the process of running Optical Character Recognition (OCR) on PDF documents. It works by creating a seamless workflow between Hazel (file automation tool) and DEVONthink Pro (document management system).
The script handles:
- Detecting when files are ready for processing (not locked by other applications)
- Launching DEVONthink Pro if not already running
- Synchronizing the database
- Applying OCR smart rules to the documents
- Providing detailed logs and status updates
- macOS
- Hazel (file automation tool)
- DEVONthink Pro 3
- PDF documents requiring OCR
- Download the
SmartOCR.scptfile from this repository - Place it in a location accessible to Hazel (e.g.,
~/Library/Scripts/Folder Action Scripts) - Configure Hazel and DEVONthink Pro as detailed below
- Open DEVONthink Pro
- Create a Smart Rule for OCR processing:
- Go to Tools → Smart Rules
- Click the + button to create a new Smart Rule
- Set up the rule as shown in the screenshot:
- Name: "OCR Ablegen" (or your preferred name)
- Search in: Select your target folder (e.g., "02 - Ablegen")
- Set conditions to match your needs (e.g., Extension is PDF, Kind is PDF/PS)
- Add an OCR action
- Optionally add a Move action to relocate processed files
- Open Hazel Preferences
- Create a new rule for the folder you want to monitor
- Set up the rule as shown in the screenshot:
- Name: "OCR via DTP" (or your preferred name)
- Set condition to match PDF files (Kind is PDF)
- Add an action to Run AppleScript and select the
SmartOCR.scptfile - No need to configure options unless you want to override default settings
The script has several configurable parameters at the top:
property CONFIG : {
databaseName:"Ablegen", -- Name of your DEVONthink database
smartRules:{"OCR Ablegen"}, -- Name(s) of your OCR smart rule(s)
sourceFolder:"/Volumes/Daten/Cloud/02 - Ablegen", -- Path to your folder
launchDelay:5, -- Seconds to wait after launching DEVONthink
syncDelay:3, -- Seconds to wait after database sync
maxRetries:25, -- Maximum retry attempts for locked files
retryInterval:5 -- Seconds between retry attempts
}Modify these values to match your specific setup.
- Hazel detects new or modified PDF files in the monitored folder
- Hazel triggers the SmartOCR script for each matching file
- The script:
- Checks if the file is locked by another process
- Launches DEVONthink Pro if not already running
- Updates the indexed folder in the DEVONthink database
- Executes the specified smart rule(s) to perform OCR
- The OCR'd document is now searchable in DEVONthink
If the script isn't working as expected:
- Check logs: Run the script manually in Script Editor to see detailed logs
- Verify paths: Ensure the folder paths in the configuration match your system
- Smart rule names: Confirm the smart rule name in DEVONthink exactly matches what's in the script
- File access: Make sure Hazel has permission to access the files and folders
You can also process multiple files at once by running the script directly in Script Editor. It will prompt you for a folder to process.
This script is released under the WTFPL License.

