Change keyboard backlight from cmd line?

This works, thanks! Is there anyway to set the led brightness too?

Just use darker colours.

1 Like

The three numbers are the RGB components (red, green, blue) in hexadecimal, and each number goes from 0 to 255 intensity (but note that instead of RGB it reads BGR, and instead of using decimal numbers it reads hexadecimal values). So “0 0 FF” means no Blue, no Green and Red at full intensity.

2 Likes

I love being able to change the keyboard color to amber from the command line with…

printf 'xLRGB\x00\x11\x30' | sudo tee /dev/hidraw0

I’ve been trying to get the same effect via a cron job by adding the code below to my su crontab and have been getting mixed results

@reboot sleep 30 && test -c /dev/hidraw0 && printf 'xLRGB\x00\x11\x30' > /dev/hidraw0

If I use double quotation marks on either side of the xLRGB portion it doesn’t work.

If I use single quotation marks on either side of the xLRGB portion it works, but only changes the keyboard color to cyan no matter the value I’ve added.

Anyone have an idea as to why this may be happening?

Try to specify the path for printf, so you are not using any shell builtin, use /usr/bin/printf instead of printf.

1 Like

Bingo! That did it. Thanks a million!

For future reference to anyone else, the code below is what worked for in my su crontab. Change the sleep value and the RGB values to whatever you desire.

@reboot sleep 10 && test -c /dev/hidraw0 && /usr/bin/printf 'xLRGB\x00\x11\x30' > /dev/hidraw0
2 Likes

I may need to move this to a new thread. I have been playing with the firmware of the keyboard and I think we could edit the firmware to have the default config unless a file is present. If “File” is present the basic color, brightness and timeout for the backlight could be adjusted and polled by the firmware for changes. Would anyone else be interested in these changes?

1 Like

Sounds good. I have a script to update mine when I update my wallpaper (using imagemagick to determine a predominant colour, and to change the brightness & saturation) - just not quite happy enough with how it’s working to share it yet.

1 Like

I’ve been trying the approach with the different approaches from this thread:

(trying pure red to make the effect really obvious)

test -c /dev/hidraw0 && printf "xLRGB\x00\x00\xFF" > /dev/hidraw0

and

printf 'xLRGB\x00\x00\xFF' | tee /dev/hidraw0

When run from a root shell, both work as expected, but when run from root’s crontab with @reboot (with additional sleep and without) it always turns the light to a mid-brightness white.

Any ideas why?

EDIT:

Nevermind, I wasn’t using absolute paths for /usr/bin/printf as described earlier in this thread. That does the trick. Sorry

Man, I now want to make the backlight go red when I am running something as the root user, and back to whatever I’d set it previously when I drop back to my user permissions… (not for every sudo invocation, just when i was in a root shell – this seems very doable)

1 Like

I quickly hacked something together for this at uni today:

Æ.: "Neat little MNT Pocket Reform hack: When I launc…" - The Wandering Shop (Mastodon post with demo video)

I used root’s .bashrc and .bash_logout to trigger the color changes when launching and closing a root shell.

It’s not perfect because it’ll return to green when you exit one root shell regardless of whether other root shells are still open. But tbh when you have multiple root shells open at the same time, something else has gone very wrong already :smiley:

3 Likes