Set Image in Find Image On Screen at Macro runtime? Screenshot or get from clipboard or something like that?

I've got a macro with a Find Image action where I frequently need to change the triggering image. Right now I'm screen grabbing it, opening the editor, pasting it in, then running. It's not the end of the world but it's annoying to have to constantly modify the macro which takes me out of the workflow.

I would much prefer to have my macro start by keystroke cmd-ctrl-4 and send clipboard to the Find Image action, or even have that as a toggle on Find Image, "ask user for image each time" or something.

Is there any way to do this?

I may have solved it for now...

I found this thread: Find Image on Screen using Clipboard Image?

Using that concept I have this which seems to work so far:

The only issue is I wanted to use local variables since they could get quite large, but when I prepend them all with local it didn't work.

1 Like

The only issue you would have with Local Variables in that macro will be the access in the Execute AppleScript action at the end. Since the Local Variables are local to the macro instance execution, you need to specify the instance when requesting the value of the variable in the AppleScript.

See AppleScript: Local & Instance Variables.

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set v to getvariable "Local testImageVar" instance kmInst
	do script v
end tell

Excellent, thanks!