Redshift With Cloudiness Adjustment

A Lobsters story on the bright blue light of displays reminded me I should post this. I use redshift to adjust the color temperature of my monitor at night so I sleep better, and I wrote a custom wrapper script to include an adjustment for how overcast it is.

 
#!/bin/bash
 
set -e # exit on error
#set -x # debugging
 
if [ `pidof /usr/bin/redshift` ] ; then exit ; fi
 
# Chicago
LAT=41.94
LONG=-87.65
 
MAX=5700
DOWNTO=4200
# Tungsten: 2700K
# Halogen: 3400K
# Fluorescent: 4200K
# Daylight: 5500K
MODE=vidmode
GAMMA=0.8
 
# figure out how overcast it is, and adjust temperature to match
TODAY=`date +%Y-%m-%d`
wget -q -O/tmp/clouds.xml "http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?product=time-series&sky=sky&lat=$LAT&lon=$LONG&begin=${TODAY}T00:00:00&end=${TODAY}T23:59:59"
OVERCAST=`echo -e 's/[^0-9]*([0-9]+)<\/value>/1/m\nt xxx\nd\n:xxx' |sed -rf - /tmp/clouds.xml |tail -n 1`
TEMP=`echo "$MAX+${OVERCAST}0" |bc`
 
redshift-gtk -l $LAT:$LONG -t $TEMP:$DOWNTO -g $GAMMA -m $MODE

Want more? I'm not as good at forgetting to update @pushcx on Twitter.