Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
hammerspoon: disable Karabiner-Elements on sleep
Trying to work around the issue noted in the comment: pqrs-org/Karabiner-Elements#1645 Possibly also related to: pqrs-org/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
Showing
with
43 additions
and 0 deletions.
@@ -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), | ||
} |