Redshift Delayed Dimming Hack
Redshift automatically winds down the color of my display as day turns to night. I don’t know if it helps me sleep as the experts say it will, but it cuts down on eye strain significantly. I only have one gripe: my display gets really red really early in the evening. That’s not even a fault of the application. My schedule and the sun share equal blame in the premature dimming of my screen.
I choose to toggle Redshift off if I’m editing images or styles since colors matter for those tasks, but I often forget to toggle it on once I’m done. I wanted a way to make sure that Redshift was enabled an hour before I go to bed on most nights so that I’d know to wind down.
D-Bus provides a great conduit for that sort of runtime inter-process communication and configuration, but Redshift doesn’t yet come with a D-Bus interface.
Three factors join forces that allow me to schedule Redshift display dimming in a less ideal way:
-
Redshift listens for
USR1
signals and toggles dimming on receipt. -
xrandr
displays current gamma information (and Redshift dims the display by altering the gamma) -
Cron scripts run by my user account have access to my XAuthority credentials.
#!/usr/bin/env bash
export DISPLAY=:0
current_gamma=`xrandr --current --verbose | grep -i gamma | awk '{print $2}' | head -1`
if [ $current_gamma != '1.0:1.0:1.0' ]
then
echo "Redshift is enabled"
else
if [ `ps -ef | grep /usr/bin/redshift | grep -v grep | wc -l` -eq 0 ]
then
echo "Redshift isn't running"
nohup gtk-redshift 1>/dev/null 2>/dev/null &
else
echo "Redshift is running but toggled off"
killall -s USR1 /usr/bin/redshift
fi
fi
In an ideal world I’d add D-Bus support to Redshift for a more elegant solution and a fun bit of C programming. It’s on my “someday maybe” list for a time when I can afford to fumble with a language I last used around 2004. In the meantime, this inelegant shell script does the job and gets me back to work on more pressing projects. Maybe it’ll work for you, too.