Skip to content

Instantly share code, notes, and snippets.

@masuidrive
Created February 4, 2009 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masuidrive/58042 to your computer and use it in GitHub Desktop.
Save masuidrive/58042 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# syntax:
# 'sudo zbright +N' increments screen brightness by N percent (N=0-100)
# 'sudo zbright -N' decrements screen brightness by N percent
# 'sudo zbright N' sets screen brightness to N percent
# 'sudo zbright' w/o any args reports current brightness
#
# note: must be run as sudo
#
# 2008-12-24 Ryan M. Eustice eustice@umich.edu
# 2009-02-23 Yuichiro MASUI masui@masuidrive.jp
# probe current brightness
ho=0x$(setpci -s 00:02.0 F4.B); # hex (0-FF)
do=$(printf "%d" $ho); # decimal (0-255)
po=$(($do*100/255)); # percent (0-100)
#echo "$ho $do $po"
if [ $1 ]; then
if [ "$(echo $1 | tr -d '\-')" != "$1" ]; then
delta=$(echo $1 | tr -d '\-');
d=$((do-delta));
elif [ "$(echo $1 | tr -d '\+')" != "$1" ]; then
delta=$(echo $1 | tr -d '\+');
d=$((do+delta));
else
d=$1;
fi
if [ $d -ge 256 ]; then
d=255;
fi
if [ $d -le 0 ]; then
d=0;
fi
h=0x$(printf "%x" $d); # hex (0-FF)
H=$(printf "%x" $h); # strip 0x hex prefix
setpci -s 00:02.0 F4.B=$H
else
echo "$ho $do $po";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment