I am trying to make a Macro that does the following:
Capture part of the screen using the built Mac OS screen capture tool (Cmd + Shift +4)
Convert the clipboard image into text via the OCR functions in Keyboard Maestro
Have the text replace the contents of the system clipboard
I am having two issues:
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.
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:
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: