My hammerspoon config.
This is working on macOS Sonoma (14.6.1) and Hammerspoon 1.0.0.
Focus on a window and press one of the following key combinations. See a video here.
hammer
+f
: Full screenhammer
+c
: Centered on screenhammer
+left
: Left Halfhammer
+right
: Right Halfhammer
+up
: Top Halfhammer
+down
: Bottom Halfhammer
+shift
+left
: Left 70%hammer
+shift
+right
: Right 70%hammer
+option
+left
: Left 30%hammer
+option
+right
: Right 30%hammer
+command
+left
: Move one screen to the lefthammer
+commmand
+right
: Move one screen to the righthammer
+s
: Maximize ("stretch") vertically
hammer
+g
: Open a new Google Chrome windowhammer
+b
: Open a new Brave Browser windowhammer
+t
: Launch a Terminalhammer
+l
: Lock screen (additional lock screen bindings in Screen Lock section below)
Caps Lock
is my Hammer key, it has a perfect location on the keyboard and I'd never use it otherwise. It acts like just another modifier key, like command
, shift
, or ctrl
, but exclusively for Hammerspoon keybindings.
Use macOS's hidutil
program to remap your keys. To do this automatically at boot, copy the file com.stevekehlet.RemapCapsLockToF18.plist
to your ~/Library/LaunchAgents
. Create that directory if it doesn't already exist, and feel free to rename the file if you don't want my name in it.
Then either reboot, or simply run:
launchctl load com.stevekehlet.RemapCapsLockToF18.plist
Now just hold down the Hammer (caps lock
) and hit f
, c
, left
, or right
, etc.
There are plenty of Hammerspoon examples of creating a "hyper" key where you press and release a key (e.g. caps lock
) and then hit another button to do what you want. If you like that, great, but I just turn caps lock
into another modifier key that allows new key combinations (e.g. hammer
+g
) that are quick and easy to press. It also works more reliably than some implementations I've seen (e.g. those that use exotic combinations of cmd
+option
+ctrl
) that can inadvertently trigger application keybindings.
macOS has a security feature called Secure Input where it prevents Hammerspoon (and applications like it, including TextExpander, Keyboard Maestro, Alfred, etc) from watching keyboard input. This can get turned on without your knowledge, for example, if a background browser window gets logged out and is sitting at a password prompt. I've added some detections for this with a menu bar indicator, and a huge alert on Hammerspoon startup to alert you. There is no way to stop this other than finding the offending window and dealing with it, either entering your password and submitting it, focusing away from that field, or closing the window.
Activate with hammer
+l
, or other hotkeys like F15
or Pause
(see the code).
- Mouse button 4 and 5 to perform Back/Forward in Chrome, Slack, Chrome, and Visual Studio for Mac.
- Hammer+mouse4 or mouse5 to move windows to left/right half of screen
- Caffeine equivalent
- Microphone and speaker indicators to confirm my Airpods are the active input/output
- Lots of little things added here and there, see the include folder for all my scripts.