Original Configuration: https://github.com/zzamboni/dot-hammerspoon
This file is written in literate programming style using org-mode. See init.lua for the generated file. You can see this in a nicer format on my blog post My Hammerspoon Configuration, With Commentary.
If you want to learn more about Hammerspoon, check out my book Learning Hammerspoon!
General variables and configuration
Global log level. Per-spoon log level can be configured in each
Install:andUse block below.
SpoonInstall: spoon 管理器，需要手动安装。
This is just a shortcut to make the declarations below look more readable, i.e.
Install:andUse instead of
WinWin: Window management with short keys after toggle on:
URL dispatching to site-specific browsers
The URLDispatcher spoon makes it possible to open URLs with different browsers.
I have created different site-specific browsers using Epichrome, which allows me
to keep site-specific bookmarks, search settings, etc. I also use Edge as my
work browser (since it integrated with my work account), while using Brave for
everything else. I also use the
url_redir_decoders parameter to rewrite some
URLs before they are opened, both to redirect certain URLs directly to their
corresponding applications (instead of going through the web browser) and to fix
a bug I have experienced in opening URLs from PDF documents using Preview.
Window and screen manipulation
The WindowScreenLeftAndRight spoon sets up key bindings for moving windows between multiple screens.
move to left screen:
ctrl + alt + cmd + <Left>
move to right screen:
ctrl + alt + cmd + <Right>
The WindowGrid spoon sets up a key binding (
Hyper-g here) to overlay a grid that
allows resizing windows by specifying their opposite corners.
cmd + alt + ctrl + g
The ToggleScreenRotation spoon sets up a key binding to rotate the external screen (the spoon can set up keys for multiple screens if needed, but by default it rotates the first external screen).
ctrl + alt + cmd + <f15>
Organization and Productivity
Capturing to Org mode(Not Response)
I now use Org-mode for task tracking and capturing. The following snippet runs
~/.emacs.d/bin/org-capture script to bring up an Emacs window which allows
me to capture things from anywhere in the system. The code is a bit convoluted
because it needs to capture the current window and restore it after the
org-capture window closes, otherwise Emacs is brought to the front.
cmd + alt + ctrl + t
System and UI
Get Current Tab Url
AClock( Disabled )
General Hammerspoon utilities
BTT_restart_Hammerspoon function sets up a BetterTouchTool widget which also
config_reload action from the spoon. This gets assigned to the
config parameter in the configuration of the Hammer spoon below, which has the
effect of calling the function with the Spoon object as its parameter.
This is still manual - the
uuid parameter contains the ID of the BTT widget to
configure, and for now you have to get it by hand from BTT and paste it here.
The Hammer spoon (get it? hehe) is a simple wrapper around some common Hammerspoon configuration variables. Note that this gets loaded from my personal repo, since it's not in the official repository.
cmd + alt + ctrl + r: reload config
cmd + alt + ctrl + y: toggle console
Caffeine: Control system/display sleep
The Caffeine spoon allows preventing the display and the machine from sleeping.
I use it frequently when playing music from my machine, to avoid having to
unlock the screen whenever I want to change the music. In this case we also
create a function
BTT_caffeine_widget to configure the widget to both execute
the corresponding function, and to set its icon according to the current state.
Finding colors( Disabled )
One of my original bits of Hammerspoon code, now made into a spoon (although I keep it disabled, since I don't really use it). The ColorPicker spoon shows a menu of the available color palettes, and when you select one, it draws swatches in all the colors in that palette, covering the whole screen. You can click on any of them to copy its name to the clipboard, or cmd-click to copy its RGB code.
Displaying keyboard shortcuts
The KSheet spoon traverses the current application's menus and builds a cheatsheet of the keyboard shortcuts, showing it in a nice popup window.
Unmounting external disks on sleep
EjectMenu spoon automatically ejects all external disks before the system
goes to sleep. I use this to avoid warnings from macOS when I close my laptop
and disconnect it from my hub without explicitly unmounting my backup disk
before. I disable the menubar icon, which is shown by default by the Spoon.