Sunday, April 11, 2021

Turning keyboard light on Ubuntu after sleep

 

One of the things that I like on the Mac I use for work is that everything seems to be well integrated, however the keyboard is pretty bad though in my opinion, at least on the model that I use. Nevertheless, the back-light feature seems to be working really nice and I wanted to model this partially on the Ubuntu. One of the things that was missing on my Ubuntu laptop is that if I turn off my keyboard back-light, it stays off even if I resume working after dark or if it was on during the night and I resume it during the day, it stays on and consumes a lot of battery. It kind of seemed a shortfall on Ubuntu side, so I decided to write a little program to start and check if I needed a back-light after sleep or not. This is based on my settings for the night mode and hours entered in the setting. The idea is that the laptop comes from the sleep and if it is in the night hours, it will automatically light my keyboard, or otherwise shut off my back-light during the day. This is only after sleep mode and it gives nice feeling to start the work. Script was placed in 

/usr/lib/systemd/system-sleep/

Since it runs under root user, you will need to replace <USER> to put in your user where night mode is configured.