sudo dmesg -w|grep "Manufacturer: Keychron K1"| xargs -I{} xset r rate 250 70
It does not work, why?
I am trying to reset keyboard settings when the keyboard is reconnected, but I cannot get dmesg -w|xargs... combination to work. It supposed to be working, for example if I do this:
while :; do echo tick; sleep 1s; done|xargs -I{} date
I will get a new time printed every second. The idea was to use dmesg -w then grep then xargs but it does not work until xargs is killed from another terminal.
Why and how to fix?
You're asking an XY(Z) problem here, see "What is the XY problem?".
Your problem X is "how do I automatically have input devices configured in Xorg when hotplugged?"
And for that you simply want to write a
xorg.conf.dInputClass rule that will make the appropriate settings for your keyboard:https://www.x.org/releases/current/doc/man/man5/xorg.conf.5.xhtml#heading9
However you misidentified this problem as problem Y "how to automatically execute a program upon hotplug?" – for that we have UDev
For that problem look at UDev rules: https://wiki.archlinux.org/title/Udev
However misidentified problem Y as the "problem" Z "how can I execute the last part of a chain if pipe redirections, when a certain string appears". Tackling that does not solve your actual problem.
This
pipes three programs together, which are all executing at the same time.
xargswaits for the end of input and then executes whatever was passed to it as parameters. Of coursedmesg -wwill never produce an end-of-file.