Last active
July 7, 2024 20:49
-
-
Save jamerst/8bf86f2660fd69413be229b28b73093c to your computer and use it in GitHub Desktop.
redshift hook script for setting external monitor brightness using ddcutil
This file contains 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
#!/bin/bash | |
# Set brightness for DDC/CI enabled monitors | |
# Originally by rnhmjoj, modified slightly by jamerst | |
# https://github.com/jonls/redshift/issues/436#issuecomment-366402503 | |
# Place in ~/.config/redshift/hooks | |
# See HOOKS section under man page of redshift for more information about redshift hooks | |
# brightness values for each period (transition is brightness inbetween, not transition time) | |
night=0 | |
transition=15 | |
daytime=50 | |
deref() { | |
eval "echo \$$1" | |
# get value of correct variable by name, i.e. if transitioning to night, get value of night variable | |
} | |
fade_to() { | |
current=$(ddcutil get 10 | cut -d, -f1 | cut -d= -f2) | |
[ "$current" -gt "$1" ] && step=-1 || step=1 | |
# set dim direction based on current brightness being greater or less than target | |
for i in $(seq "$current" "$step" "$1"); do | |
# step brightness down 1 level at a time | |
ddcutil set 10 $i -d 1 | |
ddcutil set 10 $i -d 2 | |
sleep 1 | |
done | |
} | |
if [ "$1" = "period-changed" ]; then | |
# if hook is for period changing | |
fade_to "$(deref "$3")" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
$(deref ${name})
could be relaced by${!name}
.This would make you code simpler and avoid to use
eval
which is usually not recommended.