Skip to content

Repository files navigation

ocr

Capture a screenshot, OCR it with Apple Vision framework, and print the recognized text to stdout. Single binary, zero dependencies.

Install

brew install mekedron/tap/ocr

Or build from source (requires macOS):

git clone https://github.com/mekedron/ocr.git
cd ocr
make build
# binary is at ./bin/ocr

Usage

# Capture screenshot and OCR (English)
ocr
# Specify language(s)
ocr -l ru-RU
ocr -l en-US+ru-RU
# Copy to clipboard
ocr | pbcopy
ocr -l en-US+ru-RU | pbcopy
# List supported languages
ocr languages
# Show version
ocr -v

When you run ocr, the macOS screenshot selection UI appears. Select a region, and the recognized text is printed to stdout. Press Escape to cancel.

Flags

FlagDefaultDescription
-l, --langen-USOCR language(s), e.g. en-US+ru-RU
-x, --silentDo not play sounds
-v, --versionShow version and exit

Languages

Apple Vision does not auto-detect languages. You must specify them with -l. To recognize multiple languages at once, join them with +:

ocr -l en-US+ru-RU
ocr -l en-US+de-DE+fr-FR

To see which languages are supported:

ocr languages

Keyboard Shortcut

You can bind ocr to a global hotkey using Hammerspoon (brew install hammerspoon).

Add this to your ~/.hammerspoon/init.lua:

-- Cmd+Shift+2: screenshot OCR → clipboardhs.hotkey.bind({ "cmd", "shift" }, "2", function()
localoutput=hs.execute("PATH=/opt/homebrew/bin:$PATH /opt/homebrew/bin/ocr -x -l en-US+ru-RU")
ifoutputand#output>0thenhs.pasteboard.setContents(output)
endend)

Adjust the language (-l en-US+ru-RU) and keybinding to your preference. Use -x to suppress the screenshot sound.

License

MIT

About

Screenshot OCR for macOS - capture a screen region and recognize text using Apple Vision framework. Single binary, zero dependencies. Pipe to pbcopy, wire to a Hammerspoon hotkey, or use in any shell workflow.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages