Cycle Through Application Windows on the Same Screen

My computer has 3 screens. While Cmd-` can cycle through windows of the same application – I don't like how the default behavior takes the user to other screens.

For example, let's say this is how Chrome is spread across the screens:

Screen 1
Chrome Window 1
Chrome Window 2

Screen 2
Chrome Window 3
Chrome Window 4

Screen 3
Chrome Window 5

The default Cmd-` behavior is to switch like this:

Chrome Window 1, Chrome Window 2, Chrome Window 3, Chrome Window 4, Chrome Window 5, ... Chrome Window 1 ... (and so on)

I don't like that. What I want instead is to cycle through application windows of the screen that I'm currently actively using.

So if the front window is in Screen 1, I want to cycle through windows like this:
Window 1, Window 2, Window 1, etc...

...and if the front window is in Screen 2, then this:
Window 4, Window 3, Window 4, etc...

Can this be accomplished in KM?

It seems like I would need this action:

Screen Shot 2022-03-30 at 4.03.12 PM

Unfortunately, I'm having a hard time figuring out how to determine which windows are currently on a particular screen and how to reference them.

This post may have some answers but it's making my head spin:

Hey Greg,

This kind of thing gets tricky...

There's no convenient way to discern what windows are on a given screen (that I know of), although there's a tricky way to get window data with AppleScriptObjC that I don't want to spend time trolling for at the moment.

With Keyboard Maestro you can do something like this:


Using the window count of the front app you can iterate through the windows, get the window frame of each one, and use its x, y coordinates to calculate what screen the window is on.

Filter out the windows that are on different screens, and pop-up a list of window names that are on the working screen.



If it works when nothing else will then I'm ok with going down the rabbit hole....

OK so far I've been able to grab the coordinates and names with this:

Group.kmactions (4.9 KB)
Keyboard Maestro Export

To test, I made 5 notes in as follows:

  1. Each note has their own window, scattered on my 3 screens, with the exception of Note 1, which is currently selected in the main Notes window.
  2. Every note window has been maximized to the size of the screen, with the exception of Note 5 which is minimized to the dock – but was maximized before minimizing
  3. Notes are named "Note 1" - "Note 4", and then "Note 5 minimized".

Running these actions yields:


  1. First thing to "note" is that Note 1 doesn't get a title of its own window. Not really a big deal for my purposes but worth mentioning.
  2. Note 5 has the same coordinates of other windows even though it is minimized. I'd want to filter out the minimized notes somehow.
  3. Ultimately I need an index so I can pass it to the 'Bring Window With Index X to Front' action. How can I get this?
1 Like

That note doesn't have a window – it's contained in the app window.

Unfortunately the Notes app's AppleScript dictionary is mediocre at best, so you'll have to resort to AppleScript UI-Scripting to do this.

Here's some sample code:

tell application "System Events"
   tell application process "Notes"
      tell windows
         set nameOfWindows to name
         set minimizedWindows to value of attribute "AXMinimized"
         set positionOfWindows to position
      end tell
   end tell
end tell