From 576d03a17ad4c06b6e41c0a065238a6bacdaa723 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 15 Jul 2024 09:27:20 +0100 Subject: [PATCH] feat(hammerspoon/misc): add helper to easily trigger `killall Dock` When waking macOS from sleep with multiple external monitors, it does not correctly display the wallpaper on all screens, and can sometimes get confused about window placement boundaries. The fix is to simply restart the Dock process which handles these things. This simply adds a cmd+ctrl+alt+k keybinding to trigger this via Hammerspoon. This is particularly useful in the rare occasion you wake a laptop without external displays which were disconnected when it was asleep, as it sometimes gets confused to the point it thinks there are external displays, and does not consider the internal display as part of the usable desktop space, meaning there's no way to open a terminal window to execute `killall Dock`. While this VERY rare, it does still happen, which more than justifies the few lines of lua here. --- hammerspoon/init.lua | 7 +++++++ hammerspoon/kill_dock.lua | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 hammerspoon/kill_dock.lua diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index 942f3df..d2b0fc7 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -43,6 +43,13 @@ hostconfig:init() local wm = require('window_management') wm:init() +-------------------------------------------------------------------------------- +-- Misc. Helpers +-------------------------------------------------------------------------------- + +local kd = require('kill_dock') +hs.hotkey.bind({ 'cmd', 'alt', 'ctrl' }, 'K', kd.killDock) + -------------------------------------------------------------------------------- -- The End -------------------------------------------------------------------------------- diff --git a/hammerspoon/kill_dock.lua b/hammerspoon/kill_dock.lua new file mode 100644 index 0000000..d7863c2 --- /dev/null +++ b/hammerspoon/kill_dock.lua @@ -0,0 +1,18 @@ +-- luacheck: read_globals hs + +--- === kill_dock === +--- +--- Function to kill the Dock. + +local obj = {} + +--- kill_dock.killDock() +--- Function +--- Kills the Dock by executing `killall Dock`. +function obj.killDock() + hs.alert.show('Restarting Dock...') + hs.execute("killall Dock", true) +end + +-- the end +return obj