I fake a tiling window manager on Mac with Hammerspoon, resizing to fit in specific corners/sizes:
-- resize based on ratios
function ratioResize(xr, yr, wr, hr)
return function ()
local win = hs.window.focusedWindow()
win:moveToUnit({x=xr,y=yr,w=wr,h=hr})
end
end
-- 4 corners, different sizes
hs.hotkey.bind({"cmd", "ctrl"}, "w", ratioResize(0, 0, 2/5, 2/3))
hs.hotkey.bind({"cmd", "ctrl"}, "e", ratioResize(2/5, 0, 3/5, 2/3))
hs.hotkey.bind({"cmd", "ctrl"}, "s", ratioResize(0, 2/3, 2/5, 1/3))
hs.hotkey.bind({"cmd", "ctrl"}, "d", ratioResize(2/5, 2/3, 3/5, 1/3))
And to throw windows to other monitors:
-- send to next screen
hs.hotkey.bind({"cmd", "ctrl"}, ";", function()
local win = hs.window.focusedWindow()
local screen = win:screen()
local next_screen = screen:next()
win:moveToScreen(next_screen)
end)
I use it similarly, but I add spots for side x side as well as left, center, right. I only use Hammerspoon for this and a couple tiny things, but it's completely worth it for this alone. Use math to specify window sizes & location. Insanity.
local mode = hs.screen.primaryScreen():currentMode()
local mods = {"ctrl", "alt", "cmd"} -- mash those keys
-- regular app windows
do
local w = 1094 -- no clip on GitHub, HN
local h = 1122 -- tallish
local x_1 = 0 -- left edge
local x_2 = math.max(0, (mode.w - w - w) / 2) -- left middle
local x_3 = (mode.w - w) / 2 -- middle
local x_4 = math.min(mode.w - w, x_2 + w + 1) -- right middle
local x_5 = mode.w - w -- right edge
local y = 23 -- top of screen below menu bar
hs.hotkey.bind(mods, "2", function() move_win( 0, y, mode.w, mode.h) end) -- max
hs.hotkey.bind(mods, "3", function() move_win(x_1, y, w, h) end)
hs.hotkey.bind(mods, "4", function() move_win(x_2, y, w, h) end)
hs.hotkey.bind(mods, "5", function() move_win(x_3, y, w, h) end)
hs.hotkey.bind(mods, "6", function() move_win(x_4, y, w, h) end)
hs.hotkey.bind(mods, "7", function() move_win(x_5, y, w, h) end)
end
function move_win(x, y, w, h)
hs.window.focusedWindow():setFrame(hs.geometry.rect(x, y, w, h))
end
I highly recommend Aerospace[1], went through a few approaches, I cared about not completely compromising security either, it works really well if you come from something like i3
Hammerspoon is the glue that holds my Mac together. For a starter list of things to do with this app, a partial list of the things that I'm using it for:
- Dumping all open Safari tabs to an Obsidian doc
- Adding 'hyper' (Ctrl-Opt-Cmd) keybinds to pop a new window for:
- Safari
- Finder
- Terminal / Ghostty
- VS Code
- Notes
- Editing Hammerspoon/AeroSpace/Sketchybar config
- Reloading Hammerspoon config
- Reloading Sketchybar
- Quitting all Dock apps except Finder
- Screen lock
- System sleep
- Opening front Finder folder in VS Code
- Opening front Safari URL on Archive.today
- Showing front Safari window tab count
- Showing front app bundle ID
- Posting notification about current Music track
- Controlling my Logi Litra light (various color temps/brightnesses)
- Starting/stopping a client work timer
- Tying it to AeroSpace for:
- Pushing a window to another monitor
- Performing a two-up window layout
- Swapping those two windows
- Closing all other workspace windows
- Gathering all windows to first workspace
- Ensuring some background apps stay running if they crash
- Prompting to unmount disk images if trashed
- Binding into Skim to jump to specific sections of spec PDFs using terse Markdown URLs
i've tried all of the other fancy window managers and for me nothing has ever beat the ease of use of just
(1) ctrl-d to see the grid, (2) type the letter where you want the top left corner of your window to be, (3) type the letter where you want the bottom right corner to be
Neat until you need to sync configs or keep multiple machines in harmony, at which point dotfile headaches stack up with Hammerspoon and Lua. Adding complex logic like window rules, app-specific behavior, or handling monitor changes strips away some of that hotkey simplicity and leads to endless tweaking. Still, for avoiding the mouse, it's one of the few flexible options left on macOS that doesn't feel ancient. Tradeoffs everywhere but nowhere else really compares in control.
This is amazing! I have a slightly more elaborate setup that allows me to resize from one or another side, similar to what Apple added recently but with more flexibility, but this is super interesting, thanks for sharing!
make caps lock control on hold, double quote on tap. Make control hyperkey on hold, angle bracket on tap. My keyboard firmware is very odd. This is not easily done with soft remaps to the point that I don't bother trying.
I tried to find a proper window control tool for macOS for a while, tested Rectangle and Magnet and dunno how many.
Then I just figured out that I have Hammerspoon, it can control windows -> recreate one exactly how I like it. Been using it for a year now and it's 99% perfect. Some specific applications (coughFirefoxcough) sometimes get into a weird state that doesn't work, but I can live with that.
It can also pop all windows to a specific layout with a single shortcut by combining the active wifi + monitor setup to detect if I'm at home, at work, or working at home.
I use it to hide Zoom's screen sharing controls so they don't come back when pressing Esc:
-- Hide Zoom's "share" windows so it doesn't come back on ESC keypress
local zoomWindow = nil
local originalFrame = nil
hs.hotkey.bind({"cmd", "ctrl", "alt"}, "H", function()
print("> trying to hide zoom")
if not zoomWindow then
print("> looking for window")
zoomWindow = hs.window.find("zoom share statusbar window")
end
if zoomWindow then
print("> found window")
if originalFrame then
print("> restoring")
zoomWindow:setFrame(originalFrame)
originalFrame = nil
zoomWindow = nil
else
print("> hiding")
originalFrame = zoomWindow:frame()
local screen = zoomWindow:screen()
local frame = zoomWindow:frame()
frame.x = screen:frame().w + 99000
frame.y = screen:frame().h + 99000
zoomWindow:setFrame(frame)
end
else
print("> window not found")
end
end)
local appHotkeys = {}
local function remapAppHotkey(appName, fromMods, fromKey, toMods, toKey, delay)
if not appHotkeys[appName] then
appHotkeys[appName] = {}
end
local hotkey = hs.hotkey.new(fromMods, fromKey, function()
hs.eventtap.keyStroke(toMods, toKey, delay or 0)
end)
table.insert(appHotkeys[appName], hotkey)
end
local appWatcher = hs.application.watcher.new(function(appName, eventType)
local hotkeys = appHotkeys[appName]
if not hotkeys then return end
for _, hotkey in ipairs(hotkeys) do
if eventType == hs.application.watcher.activated then
hotkey:enable()
elseif eventType == hs.application.watcher.deactivated then
hotkey:disable()
end
end
end)
appWatcher:start()
-- Remap app hotkeys
remapAppHotkey("Finder", { "cmd" }, "q", { "cmd" }, "w", 0.5)
... etc ...
otherwise I'm slowly working on a Spoon that figures out if there is an active meeting in Zoom, Teams, Huddle, Google Meet and will allow for muting, video enable/disable and screen sharing etc
My guess is someone just found it. When I was moving to macOS for my work laptop, I was looking for something to replace AutoHotKey. It took me a long time and a lot of digging to actually find HammerSpoon.
Well, a tiling window and workspace manager. But as I am typing this, I’m realizing they hammerspoon can probably do some of the window placement, but maybe not handling workspaces and global state.
I was hoping I could be lazy and ask, and a not-lazy person could give a ready made answer :)
What do you mean? Like muting the entire application so no sound comes from Teams or muting yourself while on a call? For the latter, I thought 'Option + Space' worked (or used to)?
It's fun to combine with qmk [0], which gives you a bunch more options for hotkeys on your keyboard via layers. I've ended up with a layer where half the keyboard is Hammerspoon shortcuts directly to apps (e.g. go to Slack, to Chrome, etc.) and half of it is in-app shortcuts (like putting cmd-number on the home row, for directly addressing chrome tabs).
Between this and one of the tiling window manager-adjacent tools (I use Sizeup), I can do all my OS-level navigation directly. "Oh I want to go to Slack and go to this DM" is a few keystrokes away, and not dependent on what else I was doing.
I have fond memories of this app. However, after many years, I have moved on. I am in the process of writing my own replacement for some of the various use cases that Hammerspoon once provided me. Though, Hammerspoon will always be a source of great inspiration.
I fake a tiling window manager on Mac with Hammerspoon, resizing to fit in specific corners/sizes:
And to throw windows to other monitors:I use it similarly, but I add spots for side x side as well as left, center, right. I only use Hammerspoon for this and a couple tiny things, but it's completely worth it for this alone. Use math to specify window sizes & location. Insanity.
I highly recommend Aerospace[1], went through a few approaches, I cared about not completely compromising security either, it works really well if you come from something like i3
1. https://github.com/nikitabobko/AeroSpace
Moom is really the best
How does this compare to AppleScript?
See also:
KeyboardMaestro
Automator and AppleScript
Raycast
I use it to enable/disable the wifi when I disconnec/connect the macbook to a specific usb hub with ethernet connection:
Hammerspoon is the glue that holds my Mac together. For a starter list of things to do with this app, a partial list of the things that I'm using it for:
Keyboard stuff is better handled with Karabiner elements
here is my entire config
i've tried all of the other fancy window managers and for me nothing has ever beat the ease of use of just(1) ctrl-d to see the grid, (2) type the letter where you want the top left corner of your window to be, (3) type the letter where you want the bottom right corner to be
window resized
Neat until you need to sync configs or keep multiple machines in harmony, at which point dotfile headaches stack up with Hammerspoon and Lua. Adding complex logic like window rules, app-specific behavior, or handling monitor changes strips away some of that hotkey simplicity and leads to endless tweaking. Still, for avoiding the mouse, it's one of the few flexible options left on macOS that doesn't feel ancient. Tradeoffs everywhere but nowhere else really compares in control.
This is amazing! I have a slightly more elaborate setup that allows me to resize from one or another side, similar to what Apple added recently but with more flexibility, but this is super interesting, thanks for sharing!
Not that I insert EOFs very often, but does that conflict with CTRL+D in the terminal?
Make caps lock a hyperkey (shift+ctrl+option+cmd) and use that for non-overlapping shortcuts
make caps lock control on hold, double quote on tap. Make control hyperkey on hold, angle bracket on tap. My keyboard firmware is very odd. This is not easily done with soft remaps to the point that I don't bother trying.
I use EOF all the time to end terminal sessions.
Great handle, btw.
yeah the CTRL+D definitely gives me problems from time to time but thus far i have been too lazy to fix it
I tried to find a proper window control tool for macOS for a while, tested Rectangle and Magnet and dunno how many.
Then I just figured out that I have Hammerspoon, it can control windows -> recreate one exactly how I like it. Been using it for a year now and it's 99% perfect. Some specific applications (coughFirefoxcough) sometimes get into a weird state that doesn't work, but I can live with that.
It can also pop all windows to a specific layout with a single shortcut by combining the active wifi + monitor setup to detect if I'm at home, at work, or working at home.
Moom works like a charm
I use it to hide Zoom's screen sharing controls so they don't come back when pressing Esc:
I use this to remap app keys:
I love hammerspoon. That's it :D
It's lua, so you can get creative with https://fennel-lang.org/
is there a particular reason this was shared?
otherwise I'm slowly working on a Spoon that figures out if there is an active meeting in Zoom, Teams, Huddle, Google Meet and will allow for muting, video enable/disable and screen sharing etc
My guess is someone just found it. When I was moving to macOS for my work laptop, I was looking for something to replace AutoHotKey. It took me a long time and a lot of digging to actually find HammerSpoon.
Love hammerspoon. I use it to map double CMD to swap between the terminal and the browser.
Has anyone worked on making a config replicating aerospace?
Hammerspoon seems like a superset and it’s probably better to just have one, instead of two tools warring about who gets the keypresses?
What features are you trying to replicate from Aerospace?
Well, a tiling window and workspace manager. But as I am typing this, I’m realizing they hammerspoon can probably do some of the window placement, but maybe not handling workspaces and global state.
I was hoping I could be lazy and ask, and a not-lazy person could give a ready made answer :)
I use it to give me focus-follows-mouse and to have a large circle surrounding the mouse when i move it, to aid finding it.
I always confuse "hammerspoon" and "rowhammer"
Can't live without Hammerspoon on Mac.
Can't live without AutoHotkey on Windows.
Thanks to everyone who contributed to both!
I'd love to have a global "toggle Teams mute" button.
```
hs.loadSpoon("MicMute")
binding = { toggle = { {"ctrl", "alt"}, "m" } }
spoon.MicMute:bindHotkeys(binding)
```
You'll have to add the MicMute spoon which just mean downloading the zip here, unzipping, and opening the .spoon. https://www.hammerspoon.org/Spoons/MicMute.html
What do you mean? Like muting the entire application so no sound comes from Teams or muting yourself while on a call? For the latter, I thought 'Option + Space' worked (or used to)?
I utterly love Hammerspoon.
It's fun to combine with qmk [0], which gives you a bunch more options for hotkeys on your keyboard via layers. I've ended up with a layer where half the keyboard is Hammerspoon shortcuts directly to apps (e.g. go to Slack, to Chrome, etc.) and half of it is in-app shortcuts (like putting cmd-number on the home row, for directly addressing chrome tabs).
Between this and one of the tiling window manager-adjacent tools (I use Sizeup), I can do all my OS-level navigation directly. "Oh I want to go to Slack and go to this DM" is a few keystrokes away, and not dependent on what else I was doing.
[0] https://qmk.fm/
what's your favourite spoon?
I have fond memories of this app. However, after many years, I have moved on. I am in the process of writing my own replacement for some of the various use cases that Hammerspoon once provided me. Though, Hammerspoon will always be a source of great inspiration.
Is paperwm jittery for everyone?