Having Problems With Converting Screen Shots to OCR

I am trying to make a Macro that does the following:

  1. Capture part of the screen using the built Mac OS screen capture tool (Cmd + Shift +4)
  2. Convert the clipboard image into text via the OCR functions in Keyboard Maestro
  3. Have the text replace the contents of the system clipboard

I am having two issues:

Issue 1:

When I run the Macro, it comes up with the following error:
"Ocr image cannot get target"
The error then cancels the macro.

I don’t really understand this error. The OCR is applied to the clipboard. So I am not sure why it cannot get the target.

Issue 2:

In my Macro, it uses a key stroke to trigger built in Mac OS screen capture tool (Cmd + Shift +4). It then pauses to give me time to capture the part of the screen I want.

At the moment, I am using pause until center mouse button is pressed. But ideally, I would like it to stay paused until the left mouse button is up (i.e. it was pressed down and the mouse is back up), because at that point the screen capture would be complete. That way, the macro can continue on to the OCR step without me having to make any additional button presses. How can I do this? I see no way to test if the mouse button is up.

I have attached my Macro below. It has an extra step where it opens TextEdit and pastes, just to check it is working:

Convert Screen Shots to OCR and paste in text edit.kmmacros (4.7 KB)

My environment:
Mac OS 12.6.1
Keyboard Maestro: 10.2

Instead of simulating the macOS hotkey, it's better to run the screencapture command in a shell script action with the interactive flag. This will make the macro wait until you've finished taking the screenshot before running the OCR. You can find a complete macro that already does this here:

Since you're on Monterey and KM 10.2, you could also use the built-in OCR that powers Live Text instead of the Tesseract OCR engine that KM uses. The easiest way I've found to do that is to make a Shortcut and incorporate that into the macro:


Check the contents of your clipboard! The predefined OS command for what you want to do is ⌘⌃⇧4 -- you're missing the ⌃ and probably saving to a file.

But that's just troubleshooting your current problem -- follow @gglick's advice on how to do what you want to do in a better way.

1 Like

Thank you so much gglick and Nige_S. It never dawned on me to use Shortcuts, so that was super helpful.

1 Like