Skip to content

Instantly share code, notes, and snippets.

@nickabal
Created April 11, 2016 17:30
Show Gist options
  • Save nickabal/0a3faaa45b76a53bfad76a748e27b58f to your computer and use it in GitHub Desktop.
Save nickabal/0a3faaa45b76a53bfad76a748e27b58f to your computer and use it in GitHub Desktop.
Set brightness via radeon_bl0 when redshift status changes
#!/bin/bash
# Set brightness via radeon_bl0 when redshift status changes (amdgpu,radeon)
### Set brihtness via xbrightness when redshift status changes
# Set brightness values for each status.
# Range from 1 to 255 is valid
brightness_day="255"
brightness_transition="120"
brightness_night="30"
# Set fade time for changes to one minute
fadetime=60
old_brightness_v=\$brightness_${2}
new_brightness_v=\$brightness_${3}
old_brightness=`eval echo $old_brightness_v`
new_brightness=`eval echo $new_brightness_v`
case $1 in
period-changed)
if [[ $old_brightness -gt $new_brightness ]]; then
while [[ $old_brightness -gt $new_brightness ]]; do
echo $old_brightness > /sys/class/backlight/radeon_bl0/brightness
sleep $fadetime
((old_brightness -= 1))
done &
fi
if [[ $old_brightness -lt $new_brightness ]]; then
while [[ $old_brightness -lt $new_brightness ]]; do
echo $old_brightness > /sys/class/backlight/radeon_bl0/brightness
sleep $fadetime
((old_brightness += 1))
done &
fi
;;
esac
@maandree
Copy link

You can use [ ... ] instead of [[ ... ]], or test ... as I would prefer. If you then use expr instead of (( )), the script should run nicely in POSIX sh on any system. To improve performance (assuming using sh instead of bash) but lose portability, you can use for and seq instead of the counter.

@maandree
Copy link

You may also want to look at the file max_brightness instead of assuming that the maximum value is 255, it seldom is. Some user's may want to test setting the brightness to their value on brightness_night and then reset the brightness, before putting this in production; some drives will get locked until reboot when the brightness is too low.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment