"Click at Found Image" Works from Editor, not in practice


#1

Hello,

As part of a larger routine, I need Keyboard Maestro to click on arbitrary points within this Colour Palette in Avid Pro Tools.
INIT_COL

In the KM Editor window, using the 'Go' button in the action pane, this works every time.
44

But for some reason it fails when I try to execute the macro. I get error, "[...] no unique image found"
-The editor window is hidden while I run the macro.
-I've toyed with the fuzziness sliders.

Any help in troubleshooting this would be appreciated.

Thanks.


#2

One obvious difference when you are actually trying the macro is presumably that the Avid application is at the front. It is possible that the palette changes highlighting when Avid is at the front which results in the failure to find the image. It is also possible that one of the colors in the palette is “marked” as selected or the sliders for brightness etc are different when Avid is at the front which would mess with the image match.

Another possibility is what is exposed on the screen when Keyboard Maestro is not at the front, it is possible there are other similar results on the screen that are confusing Keyboard Maestro.


#3

Hi Peter, thanks for your detailed response.

I'm not sure what you mean by 'highlighting' in this context.

This might be it. I'm gonna do some tooling around here.

So when a clip is selected in the timeline, its colour is highlighted in the colour palette like this:
47
(see the white out-line, bottom-right)

This wasn't enough to throw off the action when checking with 'go' in KM Editor, but to rule it out, I cropped the image I'm using in my macro to the following:

INIT_COL_2ROWS
This should rule out any problems instigated by slider positions. The default clip colours chosen by the program always belong in the bottom row of the palette, so by excluding them from the reference image I should negate the issue with highlighted colours in my use-case.

Unfortunately, I'm running into the same issue, where KM can locate the points in the image I need to click except in the context of the macro, with Pro Tools being the front-most active window.

I don't think so? Here is a full screenshot:

Thanks for taking the time to respond. And by the way, whatever forum software you're using is very slick and useable. It's easy to insert images and quote users.


#4

@JingleDjango you set the mouse click to coordinates in your macro (screenshot). Have you tried the action "Click at Found Image"?


#5

Hey @JingleDjango,

It's Discourse.

Try running my window properties report macro, and see if the report contains your color palette window.

If it does then perhaps you can use detection means other than click at found image.

-Chris


#6

Yes, this was my first approach. I used very small thumbnail images the size of each colour I needed to click. This didn't work either. Or rather, it would work twice in my loop and then 'find image' would fail.


#7

Great tool there, ccstone. Thanks for that. The palette window is recognized but untitled, so I'm not sure how to address it.


#8

Frequently when an application changes from being front application to not-front application, the window coloring changes slightly to indicate this. The effect can often be subtle, but it can be sufficient to throw off image matching.

So make sure you take the screenshot of the window while Avid is at the front.


#9

This is the result if I use thumbnail reference images rather than picking co-ordinates from within a larger slice of the palette.

The thumbnails I'm using:
INIT_COL_BLUE INIT_COL_ORANGE

You may have guessed, but the goal of the macro is to alternately colour each clip in the timeline. Then I'll run another macro I made that will spread each clip out by 1sec. I'm prepping sessions of hundreds or thousands of clips each to send to editors. The colour coding and spacing are visual hints to editors down the line that each clip is a discrete package of audio that must stay grouped together.

Here's what happens if I run the colour macro using thumbnails:

The first two clips get coloured correctly but then things fall apart for reasons I can't figure out yet.


#10

Okay, looks like I've got it somewhat figured out!

I still don't have the 'thumbnail' version working, but using the larger found image I found a reason why it wasn't detecting:

The macro begins with a dialog prompting the user to enter the number of clips to be coloured. The dialog appears at the center of the screen, right on top of where I've been keeping the colour palette window.

If I begin with the palette below the dialog. . .

Hello! Perfect.


#11

In that case, you could find the location before the prompt, although even then you will want a pause before the click to ensure the prompt window has gone away and the click can be validly clicked on the palette.


#12

Hey @JingleDjango,

It looks to me as though the color palette size is fixed. If so then something like this AppleScript will work.

It returns the X,Y position of the color palette window to Keyboard Maestro variables, and from there you can do relative clicks to the various color swatches.

It it works it should be very speedy and reliable.

-Chris

set paletteExists to false

tell application "System Events"
   tell application process "Keyboard Maestro Engine"
      set winPos to position of windows whose subrole is "AXFloatingWindow" and size is {549, 116}
      if length of winPos = 1 then
         set winPos to item 1 of winPos
         set {winPosX, winPosY} to winPos
         set paletteExists to true
      end if
   end tell
end tell

if paletteExists then
   tell application "Keyboard Maestro Engine"
      setvariable "X" to winPosX
      setvariable "Y" to winPosY
   end tell
else
   display notification "Color Palette NOT FOUND!" with title "Avid Pro Tools" subtitle "" sound name "Tink"
end if

#13

Thanks for that, ccstone.

Script was returning "Color Palette NOT FOUND!"

I changed "windows" in that line to "window" singular and I stopped getting the not found notification. But I'm not sure it's working right still, because it's not returning any variables to KM.


#14

Hey @JingleDjango,

Oh, that’s not too surprising. I must have been tired when I wrote that, because I forgot to change Keyboard Maestro Engine to Pro Tools.

Try this one and make sure Pro Tools is frontmost when you run it.

(It should work if run from the Script Editor, but I haven't put any delays after set frontmost to true, so it might not. Palette windows often vanish if their app is in the background.)

Oh, make sure “Pro Tools” in the script corresponds exactly to the app name.

-Chris

set paletteExists to false

tell application "System Events"
   tell application process "Pro Tools"
      set frontmost to true
      set winPos to position of windows whose subrole is "AXFloatingWindow" and size is {549, 116}
      if length of winPos = 1 then
         set winPos to item 1 of winPos
         set {winPosX, winPosY} to winPos
         set paletteExists to true
      end if
   end tell
end tell

if paletteExists then
   tell application "Keyboard Maestro Engine"
      setvariable "X" to winPosX
      setvariable "Y" to winPosY
   end tell
else
   display notification "Color Palette NOT FOUND!" with title "Avid Pro Tools" subtitle "" sound name "Tink"
end if

-Chris


#15

Chris, Peter,

You've been a huge help. Thanks for your support.