Can't match Minimize button's color on Mac

Asked by acypher

I want to click on the yellow Minimize button in the upper-left corner of windows on a Mac.
I use the 'quick capture hotkey' to capture the image.
When I run the script, it either finds no buttons, or finds the red Close button instead.
When I look at the Matching Preview, changing Similarity either results in choosing all 3 of the Close, Minimize, Maximize buttons or none of them. I did once get just the Minimize button to match with a Similarity of .64, but when I ran the script, the Close button was selected.
I think part of the problem with the Matching Preview may be that Sikuli is still the frontmost app, so only the Pattern Settings window itself actually has colored buttons, even though that window is removed from the Preview.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
acypher
Solved:
Last query:
Last reply:
Revision history for this message
acypher (acypher) said :
#1

It looks like I actually had a different problem. But putting "wait(5)" before the "click", the script works correctly.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

Working with the window title bar on a Mac is a bit tricky, since already hovering with the mouse changes the visual attributes of buttons (content, color, shaded background, ...). Thank (v)God that we at least have the capture hotkey ;-)

--- using the preview feature
Yet the most critical issue is, that the preview feature is not usable in these cases, since there is no chance, to activate the title bar of the target window while working in the preview (like switchApp() works in a script).
The only applicable trick is, to make a shot of the title bar in the suitable situation with standard Mac cmd-shift-4, load the captured image in the Mac app Preview and test your finds() and clicks() on that fake (using setShowActions(True) and hover() instead of click). Now you can use the sikuli preview feature. It is even possible to take your captures from there.

--- getting the mouse out of way
another pitfall with title bars is, that the mouse may hover somewhere on the screen, when your script runs - and this may be the titlebar of another window (getting the traffic light buttons of the "wrong" window to be switched on).
In these cases I use
hover(Location(10,10))
which moves the mouse to a location where on a Mac never happens anything.