Quick Window Positioning

About three years ago I switched OS from Windows to MacOS. One thing that surprised me was the MacOS lacks a built in feature for quick window positioning. On Windows you can use the Windows key (CMD on MacOS?) and the arrow keys to place the window quickly.

The first solution I found was the free and Open Source application “Spectacle”: https://www.spectacleapp.com/
It’s since been abandoned by the author but there’s the active fork “Rectangle”: https://rectangleapp.com/

It offers a whole bunch of shortcuts:

Rectangle App Screenshot

Personally I’m only interested in “Left Half”, “Right Half”, “Maximize”, and “Next Display”. Some of these shortcuts collide with IntelliJ default shortcuts so removing most of them helps.

Notably I only have two displays. The laptop and an external display. So there’s no difference between “Next Display” and “Previous Display” is there?

Nowadays I’ve moved over to Hammerspoon: https://www.hammerspoon.org/
It’s an automation tool for MacOS. You write your automation scripts in LUA (would have preferred javascript but OK).

I simply make use of the following for quick window positioning:

local ctrlBind = function(key, fn)
    hs.hotkey.bind({"ctrl"}, key, fn, nil, fn)

ctrlBind("w", function()
    local window = hs.window.focusedWindow()
    window:moveToUnit('[0,0,100,100]', 0)

ctrlBind("s", function()
    local window = hs.window.focusedWindow()
    window:moveToUnit(hs.layout.left50, 0)

ctrlBind("d", function()
    local window = hs.window.focusedWindow()
    window:moveToUnit(hs.layout.right50, 0)

ctrlBind("e", function()
    local window = hs.window.focusedWindow()
    local screen = window:screen()
    local nextScreen = screen:next()
    window:moveToScreen(nextScreen, 0)

I also use the MacOS settings to make caps lock behave as the CTRL modifier key:

screenshot of macOS keyboard settings dialog where Caps Lock is remapped to Control

Hammerspoon may also be used for other neat automation stuff. So if you are already using Hammerspoon (or plan to use it), this approach mitigates installing one more application.