Come across a blog on how to use OCR on a mac. The steps are as follows.

  1. open the shortcuts app in the Applications folder
  2. click + button to create a new shortcut
  3. in the right sidebar, search for “extract text”
  4. drag “Extract Text from Image” in the list of possible actions from the right side bar into the main area on the left
  5. in the “Extract Text from Image” action, click on the pale “Image” and pick “Shortcut Input”, there is a “Receive Any Input from Nowhere” action appearing above the “Extract text from Image”
  6. back to the right sidebar, search for “copy” and drag “Copy to Clipboard” action right below the “Extract Text from Image”.
  7. name your shortcut as “ocr-text”

Basically you have setup a shortcut. Now you can try out this shortcut from terminal.

$ shortcuts run ocr-text -i ~/Documents/test-image.png 

Or you can use it from Python.

import subprocess

file_path = '... some file path ...'
ocr_out = subprocess.check_output(
    f'shortcuts run ocr-text -i "{file_path}"', shell=True
)
print(ocr_out)

Now use “Cmd+V” to paste to somewhere from clipboard. Does it work?