Skip to content

Instantly share code, notes, and snippets.

@craigmbooth
Created May 3, 2020 18:46
Show Gist options
  • Select an option

  • Save craigmbooth/b2dfa5944ab0dfdf082835347045fe68 to your computer and use it in GitHub Desktop.

Select an option

Save craigmbooth/b2dfa5944ab0dfdf082835347045fe68 to your computer and use it in GitHub Desktop.
Bash snippet that changes the brightness of a monitor
#!/bin/bash
# Usage: change_brightness <device_name> (+/-)
# I use this in my i3 config to allow the brightness buttons to work on my Thinkpad
set -e
get_display_info() {
local device=$1
local key=$2
echo $(xrandr --verbose | grep -m 1 -w "$device connected" -A8 | \
grep $key | cut -f2- -d: | tr -d " ")
}
device=$1
operator=$2
current_brightness=$(get_display_info $device Brightness)
new_brightness=$(python -c "print(max([0.1, min([2.0, $current_brightness $operator 0.15])]))")
xrandr --output $device --brightness $new_brightness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment