Skip to content

Instantly share code, notes, and snippets.

@victorMoneratto
Last active October 29, 2016 12:42
Show Gist options
  • Save victorMoneratto/c29f2b62f5093674b1010f5dc6b1cde4 to your computer and use it in GitHub Desktop.
Save victorMoneratto/c29f2b62f5093674b1010f5dc6b1cde4 to your computer and use it in GitHub Desktop.
Simple bash script to change brightness on all monitors at once
#!/usr/bin/env bash
#
# ISC License
#
# Copyright (c) [year], [fullname]
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
if [ $(xrandr --verbose | egrep -q '(Bright|Gamma)') ]; then
echo 'xrandr is not installed or cannot manage monitor brightness or gamma';
exit;
fi
usage() { echo '$0 [-g] <0..1>'; exit; }
METHOD=brightness
VALUE=''
for param in "$@"; do
case "$param" in
-g|--gamma)
METHOD='gamma'
;;
-h|--help)
usage
;;
*)
VALUE="$param"
;;
esac
done
if [ VALUE = '' ]; then
usage
fi
if [ "$METHOD" = 'gamma' ]; then
VALUE="$VALUE:$VALUE:$VALUE"
fi
xrandr -q | egrep "\sconnected" | cut -f1 -d ' ' | xargs -I{} xrandr --output {} --"$METHOD" "$VALUE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment