Hi, is it possible to change keyb backlight colour from the command line (similar to hyper + trackball)? Any pointers?
thx
Yes, you can send commands to /dev/hidraw0 to control the RGB backlight.
Looks like by default you have to be root to write to /dev/hidraw0 and then this works:
echo -n -e âxLRGB\x00\xFF\x00â > /dev/hidraw0
Where 00 FF 00 is an RGB code (although it appears the order is Blue,Green,Red ?)
(check the end of main.c in the keyboard firmware source for various 4 letter commands you can send to hidraw0)
thx
tried it with sudo, but get permission denied, ⌠hmm
Sudo wonât work because it doesnât apply to the >
output redirection which gets executed in the context of your shell. You can try su -c "..."
instead of sudo
.
printf 'xLRGB\x00\xFF\x00' | sudo tee /dev/hidraw0
In POSIX sh, echo flags are undefined, so maybe instead of echo, you want to use printf in case you are writing a script that can be used by more people than just you.
Sending this command to /dev/hidraw does not work on my Pocket.
EDIT: solved on my pocket, needed a hard reset (physical power switch).
Is there a way to keep the keyboard backlight color after a restart? Using the printf command I can get the color to change, but it goes back to magenta when I restart the device.
There may be a more elegant method, but Iâd just bung the line in a bash script and have it run on boot.
Neat; where would âbashâ go in the âprintf âxLRGB\x##\x##\x##â | sudo tee /dev/hidraw0â command?
You could add it to your root cron, for example:
sudo crontab -e
then add a line like:
@reboot test -c /dev/hidraw0 && printf "xLRGB..." > /dev/hidraw0
This will execute the command on each boot. First will check that /dev/hidraw0 exists and is a character device.
Thanks for the suggestion. These are separate commands?
Say I want to make the backlight a medium intensity white. Would the commands be:
sudo crontab -e
followed by:
@reboot test -c /dev/hidraw && printf âxLRGB\x33\x33\x33â | sudo tee /dev/hidraw0
Is that correct?
fwiw I got bored of having to use sudo and wanted to do this from a user permissioned script so I added:
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0660", GROUP="plugdev"
to allow users in the plugdev
group (which my user is part of - I think thatâs default but Iâm not sure, I donât remember setting it up) to read and write to devices in the hidraw subsystem and then:
sudo udevadm control --reload-rules
sudo udevadm trigger
to pick up the new configuration.
Bear in mind these are permission changes so please make sure you understand the implications of what youâre doing before you do it!
As someone who is VERY inexperienced with any kind of Linux distro, rest assured that I do NOT understand those implications!
Is there any benefit of doing it one way versus the other? Are the commands I typed out up there going to do the trick?
Thanks for the suggestions!
I would personally go with the crontab
method, as it doesnât override any default behaviour. The other method would potentially be good to make the call directly on the command line without needing âsudoâ, but generally (especially if unsure), itâs better to leave that with system permissions as thereâs potential for security issues (albeit unlikely I suspect in this case).
Yeah to be fair I was posting that more as an FYI on this thread rather than a direct response, sorry I should have made that more clear.
Nope! You want to use the commands that @amospalla suggested!
When you use sudo crontab -e
, youâre saying âas the root userâ (sudo
) I would like to edit the crontab (crontab -e
). The crontab is the configuration file for a system process (daemon) called cron
which runs tasks at scheduled times.
This will drop you into an editor where you will be able to paste in the line. You might get asked which editor you want to use if this is your first time editing a file as root - choose nano if you donât have another preference!
The reason that you can just use > /dev/hidraw0
instead of having to | sudo tee /dev/hidraw0
is because this is rootâs crontab, so when the tasks run they will run as root with all the permissions that implies. The | sudo tee ...
trick is a way to make sure that you can output to a file owned by root when youâre running a shell thatâs only owned by the user. If you were to use | sudo tee
in the crontab it wouldnât work because itâs not interactive (i.e. it runs at a scheduled time in the background) so thereâs no terminal attached for it to ask for your password!
I got around to playing with it tonight and I was able to edit crontab using nano. I added the line:
@reboot test -c /dev/hidraw0 && printf âxLRGB\x33\x33\x33â > /dev/hidraw0
I left out the âsudo teeâ part like you said, but added the specific RGB values. I used the âwrite outâ command, closed nano, and rebooted the device, but nothing changed.
I went back into terminal, entered âsudo crontab -e,â and the cron file opened up with my command still there with the original text. It seems to have saved the command into the file, at least.
As I understand it, I am using nano to edit a file containing a command that will run every time when booting to change a setting (in this case the keyboard backlight color) so I donât have to change the setting myself every time I use the device. Am I understanding the process, at least?
Now that I have the command added to the file, how do I get it to run? This is certainly a learning experience; Iâm not used to changing settings this way.
As an experiment, I entered the command into âexecuteâ and got an error message that â@rebootâ wasnât a valid commandâIâm glad that didnât mess anything up!
Test this, open a terminal, and set yourself root:
sudo su
Then execute what you are executing within cron but manually:
test -c /dev/hidraw0 && printf âxLRGB\x33\x33\x33â > /dev/hidraw0
What happens?
I canât try that specific command right now, since Iâve been running into some hangups on booting the device, but I was able to change the backlight color from the terminal using the printf command Josch posted earlier in the thread.
Try with this root crontab entry instead:
@reboot sleep 30 && test -c /dev/hidraw0 && printf âxLRGB\x33\x33\x33â > /dev/hidraw0
It waits some seconds before attempting to set the colour.