Run macro for all windows

Hey, first time asking here, and this might be a bit out there, but... I'm trying to write a macro that positions all windows based on some logic, across three monitors.

This is what I have currently, which works for the first window of each application, but I'm not sure how to do it for all windows.

Summary of the following macro screenshots:

  • Position All Windows
    • focus each application and then invoke "Position Window by Type" which operates on the front window of the front app
  • Position Window by Type
    • Invoke "Get Target Screen", which sets the "target_screen" variable
    • Move/Resize window based on title
      • place on screen target_screen
      • set size to e.g. edge to edge, or right half of the screen

It's pretty amazing what you can get done without dropping into code, but I need some help with this one. I'm a programmer, but I haven't used applescript at all. I'd prefer to do it in the UI, but open to scripting.

Any help is appreciated!

Here is an example Macro just to give you some ideas of how you might do this. It is is NOT a finished product.

In particular you need to add Actions/Logic to better position each window in the app.

MACRO:   Move and Resize All Windows for All Apps

~~~ VER: 1.0    2018-08-04 ~~~


Move and Resize All Windows for All Apps.kmmacros (15 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.




  • Provide EXAMPLE of How to Move/Resize All Windows in All Apps
    • This is NOT Ready for Production Use
    • It is just a guide.

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.


  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:


  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
  • ADD Actions to Better Set Position of Each Window
    • ALL Actions that are shown in the magenta color


  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.



This may not be what you want, or maybe it is just another "type", but here's another macro you can use as a guide:

MACRO: Cascade All Windows for An App V2 [Example]

You could create a separate macro (I call them "Sub-Macros") for each type of window arrangement, and then call the sub-macro you want using a Execute a Macro action.

Thank you so much!

I couldn't Move/Resize to take a window number (gave a generic error, I forget what it was), but I just set it to all matching the regex . and it works well.

Maybe the Variable you were using was undefined or out of range -- this worked fine for me.

That's great! Maybe you could share your finished macro so others could benefit. See post/upload your script/macro.