Score:1

Apply udev rule on reboot if device is present

kr flag

This code must be executed each time my Keychron K1 keyboard is about to be used:

echo 2 > /sys/module/hid_apple/parameters/fnmode

The code enables Fn keys as the Keychron suggests on Linux.

I put it in a script /home/me/k1add

After hours of desperation I successfully wrote this rule:

SUBSYSTEM=="hid", ENV{HID_PHYS}=="*input0", ACTION=="add",
ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="024f", RUN="/home/me/k1add"

(I wrapped the rule text here for your convenient reading).

The rule goes to:

/etc/udev/rules.d/10-my.rules

Now if I unplug and plug back the keyboard the rule applies and I am happy. But after I restart the PC nothing happens. So what is the way here to make it run on reboot? I know I can add this code to some of the rc scripts, but then this code would execute even if I use another keyboard, which might not be a big problem but anyway I believe it's udev's work to run a script each time a device is ready.

I guessed there might be another ACTION but man udev does not list possible actions. I know I can see actions with udevadm monitor but this command can only be executed after the system is fully booted, which is too late to detect the udev action.

in flag
Where did you write that rule to? `/etc/udev/rules.d/`? If so, what is the name of the `.rules` file?
kr flag
@matigo `/etc/udev/rules.d/10-my.rules`
nobody avatar
gh flag
Put the script under /usr/local/bin/ and change the path to it in your udev rule
in flag
It may be worthwhile to change the `.rules` file to be prefixed with `99` or another "high" number as there could be some items that need to be handled before the keyboard. The `.rules` files are read in the order they appear in the directory, so items you make are generally best added to the "end" of the directory
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.