Sequential Key Strokes for Windows Management

Greetings All,

I've tried to find a discussion of this, but I've failed (perhaps due to my inability to figure out what it would be called!).

I want to use one keyboard shortcut trigger like this:

First press: Move a window to position X.
Second press: Move a window to position Y.
Third press: Move a window to position Z.

So, hold down Control, Option, and Command and hit the left arrow once: position x. Twice: position Y. Thrice: positions Z.

Is that possible?

Yes and I am sure my esteemed colleagues will give you a solution shortly. Also check out MOOM app, it may do what you want and morel.
PS Please confirm window moves are ALL on the primary screen.

The trigger hot key allows for short press, long press, tap 1,2,3 etc times.
so you could write three macros,
macro 1 if tap1 move window to pos 1
macro 2 if tap2 move window to pos 2
macro 3 if tap3 move window to pos 3

"You can configure the hot key trigger to execute when the key is tapped (press and released quickly) only on the first tap, or the second tap, or the third tap, or the fourth tap (v11.0+)." – trigger:Hot Key [Keyboard Maestro Wiki]

Then you will need to use the Manipulate a window action.

Variables in Keyboard Maestro are global and retain their value.

So the macro can track its last state in a variable and perform the appropriate behaviour in sequence, something like:

  • If variable "Next Position" is 1
    • Do Position 1
    • Set Variable "Next Position" to 2
  • Else
    • If variable "Next Position" is 2
      • Do Position 2
      • Set Variable "Next Position" to 3
    • Else
      • Do Position 3
      • Set Variable "Next Position" to 1

Alternatively, you can use the triggers tapped once tapped twice tapped 3 times. In that case when you press the hot key the first time it would always to position 1.

Alternatively, you could base the behaviour on the time the macro was last triggered (using NOW function and storing the time in a variable similar to the state stored above) and base your macro behaviour on that.

1 Like

They are global and retained by default, yes (the "Scope" section in Peter's link explains more).

Right... so that's if the OP wants to move the window through a series of screen positions (although that's not how I understood the question).

The hotkey option "Is tapped only once" (etc.) would be the choice if the OP wishes to move the window to one of three positions, depending on the number of key taps. Yes?

Ah yes, interesting.

Not necessarily. It depends on the behaviour they want, but for me I would want it to cycle through positions, so tapping it once would immediately move to position 1, then when the second tap happened it would move to position 2, and then to position 3.

And again, I'd prefer it to cycle, so if I tapped it again I'd want it to go back to position 1, which my code would do. Alternatively, you could trigger the macro on tapped once or tapped 4 times, and tapped twice or tapped 5 times (though that would require editing the XML I believe).

1 Like

Thanks, everyone! I appreciate your time!

2 Likes