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.
This commit is contained in:
Jim Myhrberg
2024-07-15 09:27:20 +01:00
parent e0e872227f
commit 576d03a17a
2 changed files with 25 additions and 0 deletions

View File

@@ -43,6 +43,13 @@ hostconfig:init()
local wm = require('window_management') local wm = require('window_management')
wm:init() wm:init()
--------------------------------------------------------------------------------
-- Misc. Helpers
--------------------------------------------------------------------------------
local kd = require('kill_dock')
hs.hotkey.bind({ 'cmd', 'alt', 'ctrl' }, 'K', kd.killDock)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- The End -- The End
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

18
hammerspoon/kill_dock.lua Normal file
View File

@@ -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