0

To be able to use my keyboard, I have to run /usr/bin/numlockx off and /usr/bin/xmodmap ~/.xmodmap-k4 whenever it connects via bluetooth. To automate this, I created the file /etc/udev/rules.d/tmp/99_keychron_fnkeys.rules:

# Keychron K4:
ACTION=="add"\
,  ATTRS{uniq}=="dc:2c:26:d4:a5:1f"\
,  ATTRS{phys}=="08:71:90:d6:8c:1e"\
,  ATTRS{name}=="Keychron K4"\
,  ENV{DISPLAY}=":0.0" \
,  PROGRAM="/usr/bin/id -u" \
,  ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority" \
,  RUN+="/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out" \
,  RUN+="/bin/echo %c >> /tmp/xmodmap.out" \
,  RUN+="/usr/bin/numlockx off" 

Saying

sudo udevadm control --reload-rules
udevadm test --action="add" /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:256/0005:05AC:0255.004B/input/input102/event6 

gives the output:

Reading rules file: /lib/udev/rules.d/99-systemd.rules
Reading rules file: /etc/udev/rules.d/99_keychron_fnkeys.rules
Invalid inotify descriptor.
Unload module index
Unloaded link configuration context.
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:256/0005:05AC:0255.004B/input/input102/event6
DEVNAME=/dev/input/event6
MAJOR=13
MINOR=70
ACTION=add
SUBSYSTEM=input
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_BUS=bluetooth
XKBLAYOUT=us,de
XKBVARIANT=,
BACKSPACE=guess
XKBMODEL=pc105
XKBOPTIONS=grp:alt_shift_toggle,grp_led:scroll
TAGS=:power-switch:
LIBINPUT_DEVICE_GROUP=5/5ac/255:08:71:90:d6:8c:1e
DISPLAY=:0.0
XAUTHORITY=/run/user/1000/gdm/Xauthority
USEC_INITIALIZED=13926008547
run: '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out'
run: '/bin/echo 1000 >> /tmp/xmodmap.out'
run: '/usr/bin/numlockx off'

So the specified commands are found and will be executed. However, when reconnecting the keyboard, I get the error messages in /var/log/syslog:

May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) config/udev: removing device Keychron K4
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (**) Option "fd" "84"
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) UnloadModule: "libinput"
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) systemd-logind: not releasing fd for 13:70, still in use
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) config/udev: removing device Keychron K4
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (**) Option "fd" "84"
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) event6  - Keychron K4: device removed
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) UnloadModule: "libinput"
May 26 18:20:15 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) systemd-logind: releasing fd for 13:70
May 26 18:20:16 computer kernel: [13925.749046] apple 0005:05AC:0255.004B: unknown main item tag 0x0
May 26 18:20:16 computer kernel: [13925.749861] input: Keychron K4 as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:256/0005:05AC:0255.004B/input/input102
May 26 18:20:16 computer kernel: [13925.750774] apple 0005:05AC:0255.004B: input,hidraw4: BLUETOOTH HID v1.1b Keyboard [Keychron K4] on 08:71:90:d6:8c:1e
May 26 18:20:16 computer systemd-udevd[13531]: input102: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13533]: input102::compose: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13531]: input102::capslock: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13532]: input102::numlock: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13535]: input102::scrolllock: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13544]: input102::kana: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer systemd-udevd[13534]: event6: Process '/usr/bin/xmodmap -verbose >> /tmp/xmodmap.out' failed with exit code 1.
May 26 18:20:16 computer /usr/lib/gdm3/gdm-x-session[2140]: (II) config/udev: Adding input device Keychron K4 (/dev/input/event6)
May 26 18:20:16 computer /usr/lib/gdm3/gdm-x-session[2140]: (**) Keychron K4: Applying InputClass "libinput keyboard catchall"

So, apparently,

  • the xmodmap call fails with exit code 1
  • the echo call doesn't cause an entry in the syslog, but the file /tmp/xmodmap.out is not created either
  • the xnumlocx call fails with exit code 1

So, I'm stuck with two questions:

  1. How can I figure out why all three commands fail?
  2. How can I make these commands run as the current user?
2
  • I'm suspicious of the lines near the top that don't have a space before the `` at the end.
    – waltinator
    May 27, 2023 at 1:18
  • @waitinator you mean the line(s) like "ATTRS{uniq}=="dc:2c:26:d4:a5:1f"\"? They seem to work fine, after all, the commands specified in the "RUN+=" lines are executed when the keyboard connects. Except that they fail ...
    – doppelfish
    May 27, 2023 at 11:57

0

You must log in to answer this question.

Browse other questions tagged .