Advertisement
Guest User

backlightx

a guest
Nov 9th, 2012
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.48 KB | None | 0 0
  1. #!/bin/bash
  2. # Dependencies: coreutils sed grep
  3. # Add `chmod 777 /sys/class/backlight/acpi_video0/brightness` to your /etc/rc.local so this script will work without root access (sudo)
  4.  
  5. where="/sys/class/backlight/acpi_video0"
  6. max=`cat $where/max_brightness`
  7. current=`cat $where/actual_brightness`
  8.  
  9. if [ "$1" == "--set" ];then
  10.     if [ ! "`echo $2 | sed 's/[a-Z]//g'`" == "$2" ];then
  11.         `dirname $0`/`basename $0`
  12.         exit
  13.     elif [ 0`echo "$2" | sed 's/.//' | grep "^[0-9]*$"` -gt 0 ] && [ ! "`echo \"$2\" | grep \"^[0-9]*$\"`" == "$2" ];then
  14.         if [ "`echo ${2:0:1}`" == "+" ];then
  15.             X=$(($current+`echo ${2:1}`))
  16.         elif [ "`echo ${2:0:1}`" == "-" ];then
  17.             X=$(($current-`echo ${2:1}`))
  18.         else
  19.             echo "${2:0:1} is not a +/-"
  20.             exit
  21.         fi
  22.         if [ $X -gt $max ];then
  23.             echo $max > $where/brightness
  24.         elif [ $X -lt 0 ];then
  25.             echo 0 > $where/brightness
  26.         else
  27.             echo $X > $where/brightness
  28.         fi
  29.         exit
  30.     fi
  31.     if [ ! "`echo \"$2\" | grep \"^[0-9]*$\"`" == "$2" ];then
  32.         echo "$2 is not a Intiger"
  33.     elif [ "$2" -lt $(($max+1)) ] && [ "$2" -gt -1 ];then
  34.         echo $2 > $where/brightness
  35.     elif [ "$2" -lt 0 ];then
  36.         echo 0 > $where/brightness
  37.     else
  38.         echo $max > $where/brightness
  39.     fi
  40. elif [ "$1" == "--get" ];then
  41.     if [ "$2" == "current" ];then
  42.         echo $current
  43.     elif [ "$2" == "max" ];then
  44.         echo $max
  45.     else
  46.         echo -e "Current: $current\nMaximum: $max"
  47.     fi
  48. else
  49.     echo -e "Usage:\n\t`basename $0` --set Int | +Int | -Int"
  50.     echo -e "\t`basename $0` --get current | max | NULL"
  51. fi
  52. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement