A macOS window management CLI. Handles display detection, coordinate math, grid layouts, window positioning, and layout saving/restoring, all from the terminal.
If you find this useful, buy me a coffee.
# Clone and symlink
git clone https://github.com/joshuaswanson/window-management-cli.git
ln -s "$(pwd)/window-management-cli/wm" ~/.local/bin/wmRequires Python 3.6+ and macOS. No dependencies.
wm displays
# Display 1 (main): 1440x900 at (0, 25)
# Display 2 (external): 2560x1440 at (1440, -540)wm grid Terminal 3x3 # 3x3 on external display
wm grid Terminal 2x2 -d main # 2x2 on MacBook
wm grid Safari 3x3 -w 0.67 -a left # left 2/3 of external
wm grid Terminal 4x2 --height 0.5 --valign top # top half, 4 columnswm arrange --app Terminal # auto-grid all Terminal windows
wm arrange --app Terminal --cols 3 --rows 3 # force 3x3
wm arrange -w 0.67 -a left # left 2/3, frontmost appwm move full # fullscreen on external
wm move left -d main # left half of MacBook
wm move right-third --app Safari # right 1/3 for Safari
wm move left --window 2 --app Safari # move a specific windowPositions: full, left, right, left-third, center-third, right-third, left-two-thirds, right-two-thirds, top-left, top-right, bottom-left, bottom-right
wm move --x -96 --y -1200 --width 1550 --height 1200 # absolute pixels
wm move --width +100 # add 100px to width
wm move --height full # full display height
wm move --x -96 --y -1200 --width 1550 --height 1200 --app cmuxAny combination of --x, --y, --width, --height works. Omitted values keep the current window position/size. Values can be absolute pixels, +N for relative offset, or full for the display dimension. Use --window N to target a specific window index.
wm resize +100 +0 # grow width by 100px, keep height
wm resize full full # full display width and height
wm resize 800 600 --app Safari # set exact dimensions
wm resize +0 +0 --window 2 --app Terminal # target specific windowwm snap # snap frontmost window to nearest 3x3 cell
wm snap --cols 4 --rows 2 --app Terminalwm list # list frontmost app's windows (with titles)
wm list --app Terminal # list Terminal windows
wm list --all # list all windows across all appsOutput includes window positions, sizes, display, and titles.
wm list --app Terminal # see window indices
wm swap 1 3 --app Terminalwm focus 3 --app Terminal # bring window 3 to frontwm save coding # save all current window positions
wm save browsing # save another layout
wm layouts # list saved layouts
wm restore coding # restore a layout
wm delete browsing # delete a saved layoutwm count --app Terminal # print number of Terminal windows
wm count # count frontmost app's windowswm close Terminal --all # close all Terminal windows
wm close Safari # close frontmost Safari window
wm quit Terminal # close all windows and quit the appUses NSScreen (via AppKit bridge) to detect displays and their coordinates, then System Events AppleScript to position windows. Handles the NSScreen-to-AppleScript coordinate conversion automatically, which is the main pain point of scripting window positions on macOS (NSScreen has Y=0 at the bottom of the main display going up; AppleScript has Y=0 at the top going down).
For Terminal, wm pre-calculates character cell dimensions from the current font metrics, so windows are sized in exact character-row/column increments with no overlap. This applies to both grid (creating new windows) and arrange (repositioning existing windows).
Layouts are saved as JSON in ~/.config/wm/layouts/.
