Skip to content

joshuaswanson/window-management-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wm

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.

Buy Me a Coffee QR

Install

# Clone and symlink
git clone https://github.com/joshuaswanson/window-management-cli.git
ln -s "$(pwd)/window-management-cli/wm" ~/.local/bin/wm

Requires Python 3.6+ and macOS. No dependencies.

Usage

List displays

wm displays
# Display 1 (main): 1440x900 at (0, 25)
# Display 2 (external): 2560x1440 at (1440, -540)

Open a grid of windows

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 columns

Arrange existing windows into a grid

wm 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 app

Move a window

wm 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 window

Positions: full, left, right, left-third, center-third, right-third, left-two-thirds, right-two-thirds, top-left, top-right, bottom-left, bottom-right

Pixel positioning

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 cmux

Any 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.

Resize a window

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 window

Snap to grid

wm snap                  # snap frontmost window to nearest 3x3 cell
wm snap --cols 4 --rows 2 --app Terminal

List windows

wm list                  # list frontmost app's windows (with titles)
wm list --app Terminal   # list Terminal windows
wm list --all            # list all windows across all apps

Output includes window positions, sizes, display, and titles.

Swap windows

wm list --app Terminal   # see window indices
wm swap 1 3 --app Terminal

Focus a window

wm focus 3 --app Terminal  # bring window 3 to front

Save and restore layouts

wm 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 layout

Count windows

wm count --app Terminal  # print number of Terminal windows
wm count                 # count frontmost app's windows

Close and quit

wm close Terminal --all  # close all Terminal windows
wm close Safari          # close frontmost Safari window
wm quit Terminal         # close all windows and quit the app

How it works

Uses 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/.

About

macOS window management CLI - grid layouts, snap, save/restore, multi-display support

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages