Skip to content

Commit 5855025

Browse files
committed
Kill Karabiner-Elements more aggressively at lock screen
So I was hoping that my hack (634d725, "hammerspoon: disable Karabiner-Elements on sleep") would make my unwanted reboot problem go away, but today it came back: https://wincent.com/snippets/1159 I actually saw the keyboard jam three times today: 1. Jammed while logged in and using the machine. Random mashing of keys -- I am not sure exactly what -- made the key repeats go away. 2. The reboot cited above. 3. Another time while logged in and using the machine: this time I managed to open the Karabiner-Elements event viewer and confirm that Karabiner wasn't even seeing the events, and that quitting Karabiner made the issue go away. In any case, I am going further in this commit, having read the Karabiner-Elements dev documentation: https://github.com/tekezo/Karabiner-Elements/blob/master/docs/DEVELOPMENT.md this leads me to believe that even though Karabiner-Elements was disabled by my previous workaround, the fact that karabiner_grabber and karabiner_observer are still running could be responsible for the ongoing issues. Rather than stop using lock screens at all (scary)... https://twitter.com/wincent/status/1067501536593539072 I'm reworking my attempted fix to kill the root-owned processes as well. This requires me to set up sudoers access so that my Hammerspoon automation can start/stop the processes without user intervention (ie. no passphrase). Let's cross our fingers and hope this works.
1 parent f7c1c9a commit 5855025

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

roles/dotfiles/files/.hammerspoon/karabiner.lua

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@
55

66
local log = require 'log'
77

8-
local trim = (function(s)
9-
return s:gsub("(.-)%s*$", "%1")
10-
end)
11-
12-
local uid = trim(hs.execute('id -u'))
13-
148
local disable = (function()
159
log.i('Disabling Karabiner')
16-
hs.execute('launchctl bootout gui/' .. uid .. ' /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist')
17-
hs.execute('launchctl disable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
10+
hs.execute('~/.zsh/bin/karabiner-kill')
1811
end)
1912

2013
local enable = (function()
2114
log.i('Enabling Karabiner')
22-
hs.execute('launchctl enable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
23-
hs.execute('launchctl bootstrap gui/' .. uid .. ' /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist')
24-
hs.execute('launchctl enable gui/' .. uid .. '/org.pqrs.karabiner.karabiner_console_user_server')
15+
hs.execute('~/.zsh/bin/karabiner-boot')
2516
end)
2617

2718
return {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# As this script will be called from Hammerspoon where the UID
4+
# environment variable is not set, grab the UID ourselves here if need be.
5+
if [ -z "$UID" ]; then
6+
UID=$(id -u)
7+
fi
8+
9+
# Depends on /private/etc/sudoers.d/karabiner-sudoers:
10+
sudo launchctl load /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist
11+
sudo launchctl load /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist
12+
13+
launchctl enable gui/"$UID"/org.pqrs.karabiner.karabiner_console_user_server
14+
launchctl bootstrap gui/"$UID" /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist
15+
launchctl enable gui/"$UID"/org.pqrs.karabiner.karabiner_console_user_server
16+
17+
echo "🐣 Karabiner-Elements bootstrapped"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
# As this script will be called from Hammerspoon where the UID
4+
# environment variable is not set, grab the UID ourselves here if need be.
5+
if [ -z "$UID" ]; then
6+
UID=$(id -u)
7+
fi
8+
9+
launchctl bootout gui/"$UID" /Library/LaunchAgents/org.pqrs.karabiner.karabiner_console_user_server.plist
10+
launchctl disable gui/"$UID"/org.pqrs.karabiner.karabiner_console_user_server
11+
12+
# Depends on /private/etc/sudoers.d/karabiner-sudoers:
13+
sudo launchctl unload /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist
14+
sudo launchctl unload /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist
15+
16+
echo "💀 Karabiner-Elements killed"

roles/dotfiles/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
var: karabiner_config
5454
verbosity: 2
5555

56+
# This is a bit random having this in here, but it's a dependency of our
57+
# Hammerspoon set-up.
58+
- name: dotfiles | set up karabiner-sudoers
59+
template: dest=/private/etc/sudoers.d/karabiner-sudoers src=karabiner-sudoers
60+
become: !!bool yes
61+
5662
# Note some nasty dependencies here between creating the symlinks (eg.
5763
# effectively creating ~/mutt/config/) and then templating into it (eg.
5864
# ~/.mutt/config/settings.mutt).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# {{ ansible_managed }}
2+
3+
{{ lookup('env', 'USER') }} ALL = NOPASSWD: /bin/launchctl load /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist, /bin/launchctl load /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist, /bin/launchctl unload /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist, /bin/launchctl unload /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist

0 commit comments

Comments
 (0)