OCR images and scanned PDFs from the command line using Apple's Vision framework. Prints recognized text to stdout — pipe-friendly, zero dependencies beyond macOS.
Built for triaging the pile of memes, screenshots, and scanned PDFs you accumulate and need to search, summarize, or route somewhere else. Inspired by macOCR (which captures screen regions to the clipboard) — ocr-file is the file-in, stdout-out counterpart that composes into shell pipelines.
Requires macOS 11+ and Xcode Command Line Tools (xcode-select --install).
git clone https://github.com/2b3pro/ocr-file.git
cd ocr-file
swiftc -O ocr-file.swift -o ocr-file
sudo mv ocr-file /usr/local/bin/ocr-file image.png # image → text on stdout
ocr-file scan.pdf # all pages, separated by form-feed (\f)
ocr-file scan.pdf --page 3 # one page
ocr-file scan.pdf --page 2-5 --dpi 300 # range, higher render DPI
ocr-file photo.heic --lang en-US --lang ja-JP # multi-language
ocr-file meme.jpg --fast # fast modeSupports any format NSImage reads (PNG, JPEG, HEIC, TIFF, GIF, BMP) plus PDF (scanned or otherwise — pages are rasterized then OCR'd).
| Flag | Description |
|---|---|
--lang <code> |
Recognition language (repeatable, e.g. en-US, ja-JP, zh-Hans) |
--fast |
Fast recognition level instead of accurate (no language correction) |
--page N or N-M |
PDF only: OCR a single page (1-indexed) or range |
--dpi N |
PDF only: render DPI (default 200; higher = better OCR, slower) |
-h, --help |
Show help |
ocr-file receipt.png | pbcopy # to clipboard
ocr-file meme.jpg | apfel "what's this about?" # triage with on-device LLM
ocr-file scan.pdf | apfel "summarize in 3 bullets" # digest a scanned doc
ocr-file page.png | grep -i "invoice" # filter
for f in *.{png,pdf}; do ocr-file "$f" > "${f%.*}.txt"; done0success1runtime failure (file not found, decode error, Vision error)2usage error
MIT