2

I want to make a keyboard shortcut to increase and the decrease the keyboard backlight brightness.

The command I have for full brightness is:

echo -n 100 > /sys/class/leds/chromeos\:\:kbd_backlight/brightness

No keyboard led brightness (off):

echo -n 0 > /sys/class/leds/chromeos\:\:kbd_backlight/brightness

If I wanted to get the current brighness I would:

cat /sys/class/leds/chromeos\:\:kbd_backlight/brightness

Whats the simplest way to increase and decrease the values by a percantage, like 12%. This seems like a fairly common task.

4
  • @Dan: -n is an echo option, so it does not output a trailing newline. It has nothing to do with the number.
    – MestreLion
    May 2 '13 at 23:27
  • There are 2 questions here: how to create a script to do calculate (and automate) those commands, and another one on how to assign such scripts to keyboard shortcuts, correct? Since they are pretty distinct and unrelated I suggest you split them in 2 questions, keeping this one for the script (which is the hardest part). The other one I'm sure there are dozens of answers already, just search for it.
    – MestreLion
    May 2 '13 at 23:36
  • By the way, Chrome OS is not supported in Ask Ubuntu :P
    – MestreLion
    May 2 '13 at 23:37
  • @MestreLion I am running 12.10 on a Chromebook Pixel... the latest 3.10-rc1 kernel just names the driver like that :)
    – Ray Foss
    May 3 '13 at 5:27
3

Script to increase and decrease brightness:

#!/bin/bash

step=12
file=/sys/class/leds/chromeos\:\:kbd_backlight/brightness

case "$1" in
    -i|--increase) ((val = +step));;
    -d|--decrease) ((val = -step));;
esac

if !((val)); then
    echo "Increase or decrease screen brighness"
    echo "Usage: ${0##*/} --increase | --decrease"
    exit
fi

read -r cur < "$file"    
((val = cur + val))

if ((val <   0)); then ((val =   0)); fi
if ((val > 100)); then ((val = 100)); fi

printf '%d' "$val" > "$file"

printf 'Before: %3d\n' "$cur"
printf 'After : %3d\n' "$val"

Could be a lot simpler for a keyboard shortcut, but I decided to make it a stand-alone script with help and args, just for fun :)

To run:

  • save it somewhere, for example ~/keyboard-brightness
  • set execute permission: chmod +x ~/keyboard-brightness
  • ~/keyboard-brightness --increase
  • ~/keyboard-brightness --decrease

Now just add them as keyboard shortcuts

4
  • Thanks! I should really get into those more. In action, pressing repeatedly
    – Ray Foss
    May 3 '13 at 6:05
  • So it worked? great! :)
    – MestreLion
    May 6 '13 at 20:49
  • I tried this script on my pixel running a native Ubuntu 13.10 install, but I end up with the following error: /sys/class/leds/chromeos::kbd_backlight/brightness: No such file or directory any suggestions?
    – user200275
    Oct 9 '13 at 19:17
  • @user200275: this script was customized for the OP's hardware. Maybe your Chromebook is different. Check the /sys tree for a file that looks related to keyboard leds (start with the /sys/class/leds/chromeos tree) and change the script accordingly
    – MestreLion
    Oct 10 '13 at 8:33

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.