User Tools

Site Tools


bash:backlight_script

I had some issues getting the onboard light control working with openbox, so I just downloaded xbacklight and wrote a quick script to control it. ALT + F8/F9.

Debug crap and everything, it's all there. Enjoy :P

Examples: /usr/bin/backlight dec /usr/bin/backlight inc (that's about it)

I'm not really using the OUTPUT variable and blabla. Maybe I'll clean it up some day. Probably not though. It's for 1 laptop, I don't really give a crap.

backlight.sh
#!/bin/bash
 
# Lockfile
LOCK="/tmp/backlight.lock"
if [ -f $LOCK ]; then
#       notify-send -t 1000 Backlight "LOCK" &
        exit
fi
touch $LOCK
TODO=$1
CURRVAL=`xbacklight -get | cut -f1 -d'.'`
 
if [ "$TODO" == "inc" ]; then
        if [ $CURRVAL -gt 89 ] && [ $CURRVAL -lt 95 ]; then
                xbacklight -inc 5
OUTPUT="Current: $CURRVAL - inc 5"
        elif [ $CURRVAL -gt 94 ] && [ $CURRVAL -lt 99 ]; then
                xbacklight -inc 1
OUTPUT="Current: $CURRVAL - inc 1"
        elif [ $CURRVAL -eq 99 ]; then
# Some kind of visual error thing here?
OUTPUT="Current: $CURRVAL - inc 0"
        else
                xbacklight -inc 10
OUTPUT="Current: $CURRVAL - inc 10"
        fi
elif [ "$TODO" == "dec" ]; then
        if [ $CURRVAL -lt 20 ] && [ $CURRVAL -gt 9 ]; then
                xbacklight -dec 5
OUTPUT="Current: $CURRVAL - dec 5"
        elif [ $CURRVAL -lt 10 ] && [ $CURRVAL -gt 4 ]; then
                xbacklight -dec 1
OUTPUT="Current: $CURRVAL - dec 1"
        elif [ $CURRVAL -lt 5 ]; then
#       continue;
        notify-send -t 1000 Backlight "Can't go any lower without breaking shit." &
#OUTPUT="Current: $CURRVAL - dec 0"
        else
                xbacklight -dec 10
OUTPUT="Current: $CURRVAL - dec 10"
        fi
else
# Some kind of visual error thing here?
        OUTPUT="what func?"
fi
 
# Update value
CURRVAL=`xbacklight -get | cut -f1 -d'.'`
notify-send -t 1000 Backlight "Brightness at $CURRVAL%" &
#notify-send -t 1000 Backlight "$OUTPUT"
rm $LOCK
bash/backlight_script.txt · Last modified: 2015/08/15 22:56 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki