macOS: How to access the Live Text OCR functionality from AppleScript/JXA?

Viewed 311

As of macOS Monterey it is possible to select text in images in Preview.

Is this OCR functionality available from AppleScript and/or JXA (JavaScript for Automation)?

enter image description here

In Script Editor.app File > Open dictionary... I selected the Preview.app and looked at the API for Standard Suite and Text Suite but there doesn't seem to be anything related to OCR. (The Text Suite apparently has to do with drawing text on picture and not text extraction.)

I have also searched for text recognition actions in Automator.app but didn't see anything suitable.

1 Answers

There isn’t (yet?) a way to directly access OCR from AppleScript, but the workaround that I’m using is to use OwlOCR. This is an app that can capture text from the screen and output it to PDF, or plant text to the clipboard. Crucially for our purposes, it can also be controlled from the command line, and you can wrap those shell commands in an AppleScript “do shell script” command.

Related