在蓝牙连接上运行命令

在蓝牙连接上运行命令

为了能够使用我的键盘,我必须在通过蓝牙连接时运行/usr/bin/numlockx off并执行/usr/bin/xmodmap ~/.xmodmap-k4此操作。为了实现此自动化,我创建了文件 /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" 

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 

给出输出:

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'

因此指定的命令被找到并将被执行。但是,当重新连接键盘时,我收到以下错误消息/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"

因此,显然,

  • 调用xmodmap失败,退出代码为 1
  • echo调用不会在系统日志中产生条目,但/tmp/xmodmap.out也不会创建文件
  • 调用xnumlocx失败,退出代码为 1

因此,我有两个问题:

  1. 我如何才能弄清楚为什么这三个命令都失败了?
  2. 我如何才能让这些命令以当前用户身份运行?

相关内容