1

I use elementary OS Freya on a macbook pro 5,3. Can keyboard backlight be turned off after some time of inactivity ?

1

You could script something using xprintidle. It will tell you how long it has been since some interaction has been done. Put it in a while loop with a sleep command so it only checks every 5 seconds or so.

You can set the backlight to 0 using this line:

echo "0" > /sys/class/leds/smc::kbd_backlight/brightness

So the script would look like:

#!/bin/bash

while true
do
sleep 6
if [[ $((5 * 60 * 1000)) -lt $(xprintidle) ]]; then 
echo "0" > /sys/class/leds/smc::kbd_backlight/brightness
fi
done

xprintidle returns the time in milliseconds so you need to do 5 minutes times 60 seconds times 1000 milliseconds. Change the 5 to something else if you want it to run after a different number of minutes. Run this script on startup and it will check every 6 seconds if it should turn off the backlight. It will use hardly any resources. Make sure to chmod +x the script to make it executable.

  • Good one! But of course it won't restore keyboard brightness. I need a more solid solution here (before start hacking around), but thank you anyway. – ounos Dec 26 '15 at 21:16
  • @ounos The brightness file stores the current value. Cat it into a variable before you change it. When the value goes back to being less than 100000 (10 seconds) echo the old value back into the file. – kagronick Dec 26 '15 at 22:57
  • Sure, I can extend script's functionality. But as I said, I 'll wait first for a more 'official' way if any. ;) – ounos Dec 27 '15 at 13:11
0

It may be different on the MacBook Pro, but on my Dell Inspirion 17, the directory /sys/class/leds/dell::kbd_backlight has several files of interest, particulary the one named stop_timeout. The current contents of this file are

$ cat /sys/class/leds/dell\:\:kbd_backlight/stop_timeout 
10s
$ 

I just tried modifying the value from 10s to 60s. I then ran xprintidle just to see if it reported any different values than it was reporting when I first looked at what the above script would be doing. The values were similar. I waited 10 seconds, and the keyboard backlight stayed on! (However the cursor in my shell stopped blinking; I'm guessing there's another file that defines that.)

I realize this isn't something official, but if it is as easy as changing a setting in a file, it's good enough for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.