If Window is on Screen(Main)?

I've been trying to figure this out, searching the forums and the wiki. Is there a way to test if the front window of an application is on a particular screen like Main/0?

This works by determining if the middle point (horizontally) is within the left and right horizontal coordinates of the specified screen. It seems to me there should be a more elegant way to determine if the selected window is on the Main screen or any particular monitor (I have 4, including the MBP's internal display).

I think you can use SCREENINDEX(Front) to get the index of the screen containing the majority of the frontmost window of the frontmost application, then compare that to SCREENINDEX(Main). So:

But I don't have a multi-screen setup to hand to test on, so I'd love to know if it works!

Thanks for the suggestion. I can't get it to work, though. It just hangs using either SCREENINDEX or SCREEN.

Test Nige_S .kmmacros (3.7 KB)

It needs to be SCREENINDEX, not SCREEN (Edit: But see @tiffle's comment below).

What happens if you actually "Run" it from KM instead of triggering via external device?

What version of KM are you on (SCREENINDEX was only introduced in v10)?

The SCREEN function requires two arguments, so your calculation should read:

SCREEN(Front,Index)=SCREEN(Main,Index)

What version of KM are you using? If it’s not 10 then that would explain why SCREENINDEX isn’t working for you.

1 Like

Same result: it hangs and never finishes evaluating the If statement.

  1. I was just trying SCREEN when SCREENINDEX didn't work.

Yup. Thanks. I forgot about that. Evaluating SCREEN(Front, Index) = SCREEN(Main,Index) also doesn't work. The If statement eventually timesout but never actually processes.

Just recreated it clean and found a second display, and it worked fine for me.

Forgive the obvious question, but I see you set Debugger to "Pause New Macros" and the screenshot shows the macro paused waiting to execute the first action (ie, it isn't even getting to the logic test). What happens if you press one of the other buttons (Continue, Step Over, Step In)?

Ugh! I missed that. I'm still setting up the new Mac and didn't realize this would be turned on by default.

Thanks for catching that. The macro now works just fine. :rofl:

1 Like