Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Dependencies: coreutils sed grep
- # Add `chmod 777 /sys/class/backlight/acpi_video0/brightness` to your /etc/rc.local so this script will work without root access (sudo)
- where="/sys/class/backlight/acpi_video0"
- max=`cat $where/max_brightness`
- current=`cat $where/actual_brightness`
- if [ "$1" == "--set" ];then
- if [ ! "`echo $2 | sed 's/[a-Z]//g'`" == "$2" ];then
- `dirname $0`/`basename $0`
- exit
- elif [ 0`echo "$2" | sed 's/.//' | grep "^[0-9]*$"` -gt 0 ] && [ ! "`echo \"$2\" | grep \"^[0-9]*$\"`" == "$2" ];then
- if [ "`echo ${2:0:1}`" == "+" ];then
- X=$(($current+`echo ${2:1}`))
- elif [ "`echo ${2:0:1}`" == "-" ];then
- X=$(($current-`echo ${2:1}`))
- else
- echo "${2:0:1} is not a +/-"
- exit
- fi
- if [ $X -gt $max ];then
- echo $max > $where/brightness
- elif [ $X -lt 0 ];then
- echo 0 > $where/brightness
- else
- echo $X > $where/brightness
- fi
- exit
- fi
- if [ ! "`echo \"$2\" | grep \"^[0-9]*$\"`" == "$2" ];then
- echo "$2 is not a Intiger"
- elif [ "$2" -lt $(($max+1)) ] && [ "$2" -gt -1 ];then
- echo $2 > $where/brightness
- elif [ "$2" -lt 0 ];then
- echo 0 > $where/brightness
- else
- echo $max > $where/brightness
- fi
- elif [ "$1" == "--get" ];then
- if [ "$2" == "current" ];then
- echo $current
- elif [ "$2" == "max" ];then
- echo $max
- else
- echo -e "Current: $current\nMaximum: $max"
- fi
- else
- echo -e "Usage:\n\t`basename $0` --set Int | +Int | -Int"
- echo -e "\t`basename $0` --get current | max | NULL"
- fi
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement