Come across a blog on how to use OCR on a mac. The steps are as follows.
- open the shortcuts app in the Applications folder
- click + button to create a new shortcut
- in the right sidebar, search for “extract text”
- drag “Extract Text from Image” in the list of possible actions from the right side bar into the main area on the left
- 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”
- back to the right sidebar, search for “copy” and drag “Copy to Clipboard” action right below the “Extract Text from Image”.
- 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?