Keyboard backlight brightness on Mac Book Pro 6,2 – Linux 3.10

In the past I didn’t manage to make Keyboard backlight to work. It wasn’t turned on at all. When I updated to two or three months ago Debian Unstable the Keyboard backlight began to work at 100%. It was annoying but I didn’t want to waste my time in that.

Now I have invested some time on controlling that brightness. The article is mainly based on Ubuntu explanation on how to use Keyboard backlight without using pommed. Their zenity based script that let you choose the prefered brightness didn’t convince me.

So based on former screen brightness control script here there is a new one.

Its filename is:

/usr/local/bin/custom-keyboardlight-macbookpro

and its content is:

#!/bin/bash

# Adapted from http://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/script-to-set-up-brightness-of-backlight-in-xfce-903704/
# Script for changing backlight brightness in /sys/class/backlight/acpi_video0/brightness
# can take values 0-15, in real (my notebook) works only values 2-15

#IMPORTANT: you must have writing rights to /sys/.../brightness (I must solute it with visudo or something like that...)
#IMPORTANT: for proper work after reboot must exist directory .bright in your home directory and file last_bright in .bright directory 

#reads content of brightness and save it into variable

BRIGHTNESS_FILE="/sys/class/leds/smc::kbd_backlight/brightness"
BRIGHT_CONF_DIR="$HOME/.keyboardbright"
LAST_BRIGHT_FILE="${BRIGHT_CONF_DIR}/last_bright"
BRIGHT=$(cat ${BRIGHTNESS_FILE})

while getopts "pmlhc" optname
 do
  case "$optname" in
   "p")
    #Add more brightness
    #BRIGHT++
    BRIGHT=$(($BRIGHT+17))
    #protect mechanism (BRIGHT must be lower or equal to 15)
     if (($BRIGHT>255))
     then
        BRIGHT=$((255))
     fi
    ;;
   "m")
    #decrease brightness
    #BRIGHT--
    BRIGHT=$(($BRIGHT-17))
    #protect mechanism (BRIGHT must be bigger or equal to 2)
     if (($BRIGHT<0))
      then         BRIGHT=$((0))
      fi         ;; 
     "l")     echo "Loading last value of brightness."     #Load last value, saved in file last_bright     
     BRIGHT=$(cat ${LAST_BRIGHT_FILE})     
     echo "Last value of brightness was: $BRIGHT"     ;;    
     "h")      echo "Help: "      
               echo "-p    Increase brightness"      
               echo "-m    Decrease brightness"      
               echo "-l    Load last brightness value"      
               echo "-c N Set to custom value"      
               echo "-h    This help"      
               echo "Programmed by: ElectricZero"      
               echo "Improved by: adrian15"      
               exit 0;      ;;     
       "c")      BRIGHT=$2      
         if (($BRIGHT>255))
         then
           BRIGHT=$((255))
         fi

     if (($BRIGHT<0))      
     then         
       BRIGHT=$((0))      
     fi      ;;     
     "?")      echo "Unknown argument, try bright -h for help"      
               exit 1;      ;;     
     *)     # Should not occur     
      echo "Unknown error while processing options"     
      exit 2;     ;;   
      esac 
      done 
      echo "Brightness set on $BRIGHT" 
     #Save variable BRIGHT into file brightness 
     echo $BRIGHT > ${BRIGHTNESS_FILE}
     #Save variable BRIGHT into file last_bright
    if [ ! -d ${BRIGHT_CONF_DIR} ] ; then mkdir ${BRIGHT_CONF_DIR} ; fi
    echo $BRIGHT > ${LAST_BRIGHT_FILE}

as you might see there are some changes. Now I don’t mind having a 0 value because I actually want the keyboard not to bright at all. That’s different from an screen when you don’t want to miss it as a turned off one or non working one.

I have modified the script as always so that with only 15 types I can go from turned off to turned on at maximum brightness.

Then we need sudo so that we can run it as normal user.

So we edit sudo with the command:

sudoedit /etc/sudoers

so that we add:

normaluser ALL= NOPASSWD:/usr/local/bin/custom-keyboardlight-macbookpro

to it.

Now in my case as I use KDE I needed to setup its shortcuts to use it.

  • Preferences
  • Shortcuts and gestures
  • Custom Shortcuts

 

Then:

  • Right click and select New group which we will name: Keyboard brightness

Now we are going to setup the Increase Keyboard brightness shortcut.

  • Right click on Keyboard brightness
  • New
  • Global shortcut
  • Order / Url

so that we inform:

  • Name of the shorcut: Increase Keyboard brightness
  • Launcher tab: Short cut. I click on None and then I type “Increase keyboard brightness” button.
  • Action tab. Order / Url: sudo /usr/local/bin/custom-keyboardlight-macbookpro -p

Now we are going to setup the Decrease Keyboard brightness shortcut.

  • Right click on Keyboard brightness
  • New
  • Global shortcut
  • Order / Url

so that we inform:

  • Name of the shorcut: Decrease Keyboard brightness
  • Launcher tab: Short cut. I click on None and then I type “Decrease keyboard brightness” button.
  • Action tab. Order / Url: sudo /usr/local/bin/custom-keyboardlight-macbookpro -m

 

Now we just nee to make sure they are activated so that both of these shortcuts have ticks on them.

 

And that’s it you can control Keyboard brightness from your keyboard.

I think that I might even run: /usr/local/bin/custom-keyboardlight-macbookpro -p at kde start so that old keyboard value persists. Why? Because the default value is the backlight being on 100% while I prefer it to be turned off.

Anuncios

Etiquetas: , , , , , , , ,

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s


A %d blogueros les gusta esto: