Skip to content

Instantly share code, notes, and snippets.

@munkiwarra
Last active February 5, 2022 07:54
Show Gist options
  • Save munkiwarra/c119e459d3919b3d97cd1fd821956a88 to your computer and use it in GitHub Desktop.
Save munkiwarra/c119e459d3919b3d97cd1fd821956a88 to your computer and use it in GitHub Desktop.
Set redshift temperature and brightness
#!/bin/bash
temperatureFilePath=~/.config/redshift/TEMPERATURE
brightnessFilePath=~/.config/redshift/BRIGHTNESS
TEMPERATURE=$(cat ${temperatureFilePath})
BRIGHTNESS=$(cat ${brightnessFilePath})
MAX_TEMPERATURE=4000
MIN_BRIGHTNESS=0.5
if [ "${TEMPERATURE}" == '' ] || [ "${TEMPERATURE}" -gt 5000 ]; then
TEMPERATURE=${MAX_TEMPERATURE}
fi
if [ "${BRIGHTNESS}" == '' ]; then
BRIGHTNESS=1
fi
while getopts v:m: flag
do
case "${flag}" in
v) var=${OPTARG};;
m) mode=${OPTARG};;
esac
done
if [ "$var" == 't' ]; then
if [ "$mode" == 'i' ] && [ "${TEMPERATURE}" -lt 5000 ]; then
TEMPERATURE=$((${TEMPERATURE}+100))
fi
if [ "$mode" == 'd' ] && [ "${TEMPERATURE}" -gt 1000 ]; then
TEMPERATURE=$((${TEMPERATURE}-100))
fi
echo ${TEMPERATURE} > ${temperatureFilePath}
fi
if [ "$var" == 'b' ]; then
if [ "$mode" == 'i' ] && (( `echo "${BRIGHTNESS} < 1" | bc -l` )); then
if (( `echo "${BRIGHTNESS} < 1" | bc -l` )); then
BRIGHTNESS=`echo "$BRIGHTNESS + 0.05" | bc -l`
fi
fi
if [ "$mode" == 'd' ] && (( `echo "${BRIGHTNESS} > ${MIN_BRIGHTNESS}" | bc -l` )); then
BRIGHTNESS=`echo "$BRIGHTNESS - 0.05" | bc -l`
fi
echo ${BRIGHTNESS} > ${brightnessFilePath}
fi
#notify-send "Redshift ${REDSHIFT_TEMP}k"
redshift -P -O ${TEMPERATURE} -b ${BRIGHTNESS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment