Last active
August 29, 2015 14:24
-
-
Save elasticjava/f9fe438d29718aba1d45 to your computer and use it in GitHub Desktop.
dim all your connected shiny bright displays via bash comfortably after you checked that xbacklight really doesn't work on your hardware: use "bright" :-)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # sets the brightness via xrandr on all connected displays | |
| # requirement: {sudo apt-get update && sudo apt-get install x11-xserver-utils zenity} | |
| # installation: copy "bright" to ~/bin/ and {chmod +x ~/bin/bright} it | |
| # usage: "bright" without args shows a zenity scroll dialog using this script | |
| # author: https://github.com/hbartnick 2015 | |
| function set_brightness { | |
| for output in ${outputs[@]}; do | |
| xrandr --output $output --brightness $1 | |
| done | |
| } | |
| function cancel_hook { | |
| "$@" | |
| local status=$? | |
| if [ $status -ne 0 ]; then | |
| set_brightness $cur | |
| fi | |
| return $status | |
| } | |
| outputs=($(xrandr --verbose|grep -oP '^.*(?= connected)')) | |
| if [[ -t 0 ]]; then | |
| if [[ "$1" == "-n" ]]; then | |
| xrandr --verbose | grep -m 1 -i brightness | cut -f2 -d ' ' | |
| exit 0 | |
| fi | |
| if [[ -z $1 ]]; then | |
| cur=$(command $BASH_SOURCE -n) | |
| cancel_hook zenity --scale --title="brightness" --text="" --value=$(echo "(${cur}*100)/1"|bc) --print-partial | { | |
| while read x; do | |
| echo "scale=2;${x}/100" | bc | command $BASH_SOURCE; | |
| done | |
| } | |
| else | |
| set_brightness $1 | |
| fi | |
| else | |
| while read f ; do | |
| set_brightness $f | |
| done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment