keyboard backlight not working linux 1

keyboard backlight not working linux

#!/bin/bash
# Adjust the keyboard backlight level

shopt -s -o nounset

declare -i KBD_BACKLIGHT_MAX=`cat /sys/class/leds/asus\:\:kbd_backlight/max_brightness`
declare -i KBD_BACKLIGHT_LEV=`cat /sys/class/leds/asus\:\:kbd_backlight/brightness` 

# We need a parameter, etiher inc or dec
if [ $# -eq 0 ] ; then
   exit 192
fi 

case $1 in
-inc ) 
   # increasing:
   if [ ${KBD_BACKLIGHT_LEV} -lt ${KBD_BACKLIGHT_MAX}  ] ; then
      KBD_BACKLIGHT_LEV=${KBD_BACKLIGHT_LEV}+1
      echo ${KBD_BACKLIGHT_LEV} | tee /sys/class/leds/asus::kbd_backlight/brightness
   fi
   ;;
-dec )
   # decreasing:
   if [ ${KBD_BACKLIGHT_LEV} -gt 0 ] ; then
      KBD_BACKLIGHT_LEV=${KBD_BACKLIGHT_LEV}-1
      echo ${KBD_BACKLIGHT_LEV} | tee /sys/class/leds/asus::kbd_backlight/brightness
   fi
   ;;
esac

exit 192

Here is what the above code is Doing:
1. It’s checking to see if the user has passed in a parameter. If not, it exits.
2. It’s checking to see if the parameter is either -inc or -dec. If not, it exits.
3. It’s reading the current keyboard backlight level from the /sys/class/leds/asus::kbd_backlight/brightness file.
4. It’s reading the maximum keyboard backlight level from the /sys/class/leds/asus::kbd_backlight/max_brightness file.
5. It’s checking to see if the current keyboard backlight level is less than the maximum keyboard backlight level. If so, it increments the current keyboard backlight level by 1 and writes the new value to the /sys/class/leds/asus::kbd_backlight/brightness file.
6. It’s checking to see if the current keyboard backlight level is greater than 0. If so, it decrements the current keyboard backlight level by 1 and writes the new value to the /sys/class/leds/asus::kbd_backlight/brightness file.

Now, let’s save the above code to a file called kbd_backlight.sh.

Next, let’s make the file executable:

chmod +x kbd_backlight.sh

Now, let’s test the script:

./kbd_backlight.sh -inc

If all goes well, the keyboard backlight should increase by 1.

Let’s test the script again:

./kbd_backlight.sh -dec

If all goes well, the keyboard backlight should decrease by 1.

Now, let’s create a keyboard shortcut to run the script.

First, let’s open the Keyboard Shortcuts window:

gnome-control-center keyboard

Next, let’s click on the + button to add a new keyboard shortcut.

Next, let’s enter the following information:

Name: Increase Keyboard Backlight
Command: /home/username/kbd_backlight.sh -inc

Next, let’s click on the + button to add a new keyboard shortcut.

Next, let’s enter the following information:

Name: Decrease Keyboard Backlight
Command: /home/username/kbd_backlight.sh -dec

Now, let’s click on the Disabled button next to the Increase Keyboard Backlight shortcut and press the keyboard shortcut that we want to use to increase the keyboard backlight.

Now, let’s click on the Disabled button next to the Decrease Keyboard Backlight shortcut and press the keyboard shortcut that we want to use to decrease the keyboard backlight.

Now, let’s click on the Close button.

Now, let’s test the keyboard shortcuts.

If all goes well, the keyboard backlight should increase or decrease when we press the keyboard shortcuts.

Now, let’s create a keyboard shortcut to toggle the keyboard backlight on and off.

First, let’s open the Keyboard Shortcuts window:

gnome-control-center keyboard

Next, let’s click on the + button to add a new keyboard shortcut.

Next, let’s enter the following information:

Name: Toggle Keyboard Backlight
Command: /home/username/kbd_backlight.sh -toggle

Now, let’s click on the Disabled button next to the Toggle Keyboard Backlight shortcut and press the keyboard shortcut that we want to use to toggle the keyboard backlight.

Now, let’s click on the Close button.

Now, let’s test the keyboard shortcut.

If all goes well, the keyboard backlight should toggle on and off when we

Similar Posts