Keyboard Maestro Windows management scripts for laptops and desktops

Hopefully I’m posting this in the right spot. :smile:

I’ve been spending some of my Christmas break (I’m a college professor in upstate NY) going a bit deeper into KM. I love the idea of scripting windows for various setups (email, course management work, grading, etc.). As I’m sure is the case with many people, I work on a desktop (in my case, M1 iMac with an external display) and a laptop (M2 Macbook Air).

For those of you who are power users of KM and use it for things like window management, do you find that you have to create two sets of window setups – one group of setups (Palette?) for when you are on your laptop and another for your desktop? For example, my grading setup on my M2 Air is going to be a lot different on a small monitor than when I’m working on my iMac with an extra monitor and can put various windows on the external display. Before I commit to the extra step of making two sets of “setups” I just want to make sure I’m not missing something.


Have you looked at Moom for window placements. Moom setups can be assigned to keyboard shortcuts, which keyboard maestro call replicate.


I have a single macro that sizes and positions windows differently depending on which Mac I’m working at. The key is to get the width of the screen and choose the window size and position parameters based on whether the screen width is desktop- or laptop-sized.


There’s some information on the keyboard Maestro forum that might be useful

My personal experience is that running Moom snapshots from KM works fine if it’s fairly standard.
For more complicated and multi monitor setups sticking with KM alone is less of a fiddly issue

Unfortunately window management on the mac is one area where macOS is lagging behind linux, where window/tiling managers are more commonplace.

1 Like

This was one of the alternatives I had been considering. If it would be easier to navigate between laptop and desktop setups on Moom, then that might be the route to go. I am basing the KM question on the fact that I have been using David’s Field Guide, where he talks about the use of palettes for this.

Depending on what you are trying to do, there are a number of things you might do. Here are a few disjointed thoughts…

  1. If you are looking to accomplish everything in KM, there are some built in actions that position windows, as well as the ability to specify the exact window coordinates and size. These actions, as far as I can tell, are most usefully applied to the front window.

When doing this in KM, a problem is that as far as I have discovered so far, there is no way to easily determine what of multiple attached screens a given window is on. KM numbers the screens from 1 to N, with 0 being the “main” screen, and one of the numbers 1…N will also be that same main screen. It is not easy to figure out which screen number goes to which attached screen, however.

What I have done is to write a number of utility macros. One figures out which screen the front window is on. It does this by getting the coordinates of the top left corner of the window and then scanning all attached screens to see which screen’s bounds contain that corner.

I also have another macro that positions a window on a specified screen. It allows you to specify the desired screen (numbered 1…N), a grid pattern for the screen (rows and columns), the row/column for the top left of the window, and the number of rows and columns the window spans.

Using this macro I can easily put a window in the top left corner, top third, left third, etc, as desired.

I then have a palette of macros that use these utility macros to position windows, as well as macros that will open a set of apps and position their front windows. For example, on my desktop, a macro that is run every few minutes makes sure that my left hand monitor (of three) has OmniFocus full height left 1/3, Mail full height right 2/3, and my rightmost monitor has Messages in the top right corner and Calendar in the bottom right corner.

Obviously this macro is only useful on my Desktop with three monitors. One problem is that there is no way to figure out the screen number of the left, middle, or right monitors other than empirically, so if I were to rearrange the connections to my Mac Studio this macro would have to be changed.

  1. Better touch tool also has window positioning actions, including preset actions such as left 1/3, top 1/2 etc, plus a custom positioning / sizing action and options to move between screens. I presently have a bunch of keyboard shortcuts for some of these actions that I use the most, and also a pop-up menu for less used window positions. Thus, I use a mix of BTT and KM for different positioning purposes.

  2. There are special purpose apps, like the ones already mentioned (Moom, Rectangle, etc) that are in general very good, and I know you can trigger a recorded window position layout in Moom via AppleScript and hence from KM. I played with Moom, but it did not meet my needs primarily because I wanted to have a way of having some windows take up thirds, some quarters, some halves, etc, and with Moom as far as I can tell you can have only one grid specified that applies to all layouts, but my KM macros let me use any grid layout I want for any given macro, so I needed some KM-fu to get what I wanted.

I should perhaps note that I also have these KM macros assigned to a layout on my StreamDeck…

Now, I know I have done nothing to address your question - how to make these things work differently on laptop vs desktop.

Two obvious solutions in KM:

  1. If your desktop has >1 screen but your laptop is only used with the built-in display (or in general your desktop has a different number of screens than your laptop) the you can code your window macros in KM to check the number of screens and execute different actions depending on the screen count;
  2. You could create two macro groups of window positioning actions, one for each computer. Because macro groups can be disabled on a per-computer basis, just disable the one you don’t need on each computer.

Right now BTT has syncing between computers only on an experimental basis, so for now you would create actions separately on each computer which also would work for you, but once they have syncing working (and I do intend to use it), hopefully they will have a way to designate some actions as restricted to one computer or the other.

Lots of ramblings. I hope some of this helps.

Perhaps it’s useful to point that, with KM, you can disable/enable macros on a device basis. Instead of performing screen dimensions calculations you could set up abslute dimensions in two versions of the macro and enable specific versions on specific computers.

I think you will find that with Keyboard Maestro, you can accommodate single or multiple displays with the same window management macro(s). I’ve done it for years, using the same macros sync’d between my dual-screen desktop and my laptop.

Three tips:

  1. Keyboard Maestro knows how many displays you have going
  2. Keyboard Maestro knows what your display resolutions are.
  3. Use % of display size rather than fixed pixels when moving windows. This is empowering: My desktop system has two displays, one portrait and one landscape. With a trackpad gesture (Better Touch Tool also rocks) I can slide a window from one display to the other and it will adjust it’s size to keep the same proportions on the new display

You can do it! Good luck.


This is very intriguing, @arasmus.

Can you explain how you are accomplishing this?


  1. How are you triggering a macro based on a window moving to a different display?
  2. How are you determining the window’s size relative to the display size prior to the move? (eg initial percentages)
  3. How are you scaling the window to the same percentage of the screen on the new display?

I have played a bit with KM tonight, but have not found a way to do any of these.

With this information I might rewrite my window management system, although it does work as is…but is overly complicated, perhaps.

Also, I have moved my current window sizing scheme to BTT, where I have keyboard shortcuts plus a popup menu that accomplishes the major window positioning that I need. There are many ways to accomplish all of this, and both KM and BTT are useful tools for this purpose.

@pantulis: Agreed that if the goal is different sizing depending on laptop vs desktop, macro groups that are enabled for a specific machine is very handle. I did mention that in my overly long posting, but I assumed it was buried in a mass of irrelevance.

Right now I am fine tuning an action in BTT when Finder is active to open two windows and tile them to the left and right halves of the screen. I use this window layout a lot when moving files around, and having a gesture to make this efficient is helpful. Interesting, as far as I can tell, you cannot create a custom trackpad gesture in BTT even though it does have a library of built-in gestures to use as triggers, while in KM you can make a custom gesture, but it is somewhat cumbersome. Again, two different tools, each slightly different, and one vs the other is useful depending on what you specifically need. I think having both is quite effective!

1 Like

This is really good. Thanks so much. I need to process it a bit. :smile: