Skip to content

Instantly share code, notes, and snippets.

@darvin
Created October 27, 2015 05:55
Show Gist options
  • Save darvin/b3c53af7f28d674a1777 to your computer and use it in GitHub Desktop.
Save darvin/b3c53af7f28d674a1777 to your computer and use it in GitHub Desktop.
#!/bin/bash
# AMOUNT_OF_DISPLAYS=`ddcctl -h 2>&1 | perl -ne 'print "$1\n" if m/found (\d+) displays/;'`
CURRENT_BR_FILE=/tmp/.last.brightness
MAX_BR=100
MIN_BR=0
if [ -f "$CURRENT_BR_FILE" ]
then
CURRENT_BR=`cat $CURRENT_BR_FILE`
else
CURRENT_BR="35"
fi
BR_INCREMENT=5
case "$1" in
"up" )
CURRENT_BR=$(($CURRENT_BR+$BR_INCREMENT))
;;
"down" )
CURRENT_BR=$(($CURRENT_BR-$BR_INCREMENT))
;;
*) echo >&2 "Invalid option: $1"; exit 1;;
esac
if [ "$CURRENT_BR" -gt "$MAX_BR" ]
then
CURRENT_BR=$MAX_BR
fi
if [ "$CURRENT_BR" -lt "$MIN_BR" ]
then
CURRENT_BR=$MIN_BR
fi
echo "New brightness is $CURRENT_BR"
echo "$CURRENT_BR" > $CURRENT_BR_FILE
/usr/local/bin/ddcctl -d 1 -b $CURRENT_BR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment