Ubuntu: Keyboard backlight command by percentage



Question:

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.


Solution:1

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »