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.
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.
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:
(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:
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.
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.
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.
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.
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:
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 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.
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.
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
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.
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