Permalink
Browse files

hammerspoon: disable Karabiner-Elements on sleep

Trying to work around the issue noted in the comment:

  tekezo/Karabiner-Elements#1645

Possibly also related to:

  tekezo/Karabiner-Elements#545

Seems that under high CPU load (which might be happening at wake-up
time) Karabiner may be exacerbating a tendency of the OS to jam the
keyboard. I've had a number of hard-resets as a result of this lately:

  https://wincent.com/snippets/1159

The commands used to enable/disable here taken from:

  https://github.com/tekezo/Karabiner-Elements/blob/b38990db3/src/share/launchctl_utility.hpp#L18-L43
  • Loading branch information...
wincent committed Nov 24, 2018
1 parent 1d95a25 commit 634d7257e2e6219c516c578d789f81164a0d2738
Showing with 43 additions and 0 deletions.
  1. +2 −0 roles/dotfiles/files/.hammerspoon/init.lua
  2. +41 −0 roles/dotfiles/files/.hammerspoon/karabiner.lua
@@ -5,6 +5,7 @@ hs.window.animationDuration = 0 -- disable animations
local events = require 'events'
local iterm = require 'iterm'
local karabiner = require 'karabiner'
local log = require 'log'
local reloader = require 'reloader'
@@ -348,6 +349,7 @@ end)
hs.urlevent.bind('screencast', prepareScreencast)
iterm.init()
karabiner.init()
reloader.init()
initEventHandling()
events.subscribe('reload', tearDownEventHandling)
@@ -0,0 +1,41 @@
--
-- Attempted workaround for:
-- https://github.com/tekezo/Karabiner-Elements/issues/1645
--
local events = require 'events'
local log = require 'log'
local trim = (function(s)
return s:gsub("(.-)%s*$", "%1")
end)
local uid = trim(hs.execute('id -u'))
local disable = (function()
log.i('Disabling Karabiner')
hs.execute('launchctl bootout gui/' .. uid .. ' /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist')
hs.execute('launchctl disable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
end)
local enable = (function()
log.i('Enabling Karabiner')
hs.execute('launchctl enable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
hs.execute('launchctl bootstrap gui/' .. uid .. ' /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist')
hs.execute('launchctl enable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
end)
return {
init = (function()
local watcher = hs.caffeinate.watcher.new(
function(event)
if event == hs.caffeinate.watcher.systemWillSleep then
disable()
elseif event == hs.caffeinate.watcher.screensDidUnlock then
enable()
end
end
)
watcher:start()
end),
}

0 comments on commit 634d725

Please sign in to comment.