⌘ Getting started with Keyboard Maestro – Positioning windows
Another easy macro to get started with is positioning windows. Since I have multiple monitors, two in landscape, two in portrait, I have a specific layout for my apps. For example, I want TextSoap, at a specific size, and specific position on my first vertical monitor.
Instead of me having to move and resize the window, I can have Keyboard Maestro do it.
In fact, we’ve looked at this macro before, but it’s worth revisiting as we work toward making workspaces. We’re going to us Keyboard Maestro to help find the size and position of the windows once we have the correct layout.
The first step is to arrange windows in the desired location and at the correct size. For me, this would be positioning TextSoap, where I want it on the vertical monitor.
That done, it’s time to create a simple macro to record the window locations so they can be used in another macro.
Keyboard Maestro has built-in commands to display the window name, position, and size. We’ll use these to capture the coordinates of the window. The calculated values we’re going to use are:
We can now make a macro like this to record the screen positions.
By default this macro should be off. It should only be set to trigger when you’re grabbing window coordinates, otherwise it will pop up dialog boxes every time you click an app window.
From the trigger, this macro will execute when the window focus changes. As you click different windows, the name and position are displayed in a Keyboard Maestro result window.
With all the window positions recorded, the next step is to use the Move a Window block to set those values.
After moving a window, it can be resized using the Custom position and size.
Now that we have the correct position for TextSoap recorded, we can make a quick macro to get it into position. First we move the window to the correct position, then resize it.
One thing to note, the window position is a negative number. This is the position relative to 0,0 (top, left) of the main screen. If I were going to the right, toward the other landscape monitor, this would be positive. Since we are going left, to the vertical monitor, the values are negative.
Repeat this same process for each window you want to snap into place.
This takes some manual effort to set this up, but once it’s done, your desktop can look however you like. You can then run the macro and all the windows will be returned to their position. This is very helpful after a system restart, and keeps things consistent.
You can read more on Window Frames and moving windows at this Wiki entry.