Change windows desktop background for day and night (Ubuntu, GNU/Linux)

Having a bright, blue wallpaper for day use and a darker, reddish wallpaper for evening/night is useful stay in synch with the real time of day. So, i wanted my windows xp machine automatically switch to the day wallpaper from 7-20 and to night from 20-7 hours. The following batch script does this, without any add-on software. To use, copy-paste the file and store it to your scripts directory (e:\etc in my case).

Advantages:

  • No additional software (apart from the script) has to be installed
  • No additional load on the computer by a desktop switcher, except from the tasks that you define yourself

Notes:

  • Configuration is by changing the times in the case, and the image file names in the gconf…
  • Test by calling the script
  • Use f.lux to change the color temperatur of your display to suit the time of day → http://www.stereopsis.com/flux/
  • To automate the wallpaper switch on startup and during the day
    • Add the xdbus.sh script to your startup scripts, so that the xdbus variables are available.
    • add a cron task (see below)
changedesktop.sh
#!/bin/bash                                                                                                       
# Change desktop background image depending on the time of day                                                    
# Configuration: Change hourse in the case statements, and the images to load as background                       
#                                                                                                                 
# load variables for gconftool. These have to be written to Xdbus during login                                    
. $HOME/.config/Xdbus                                                                                             
 
HOUR=$(date +%H)                                                                                                  
gconftool=/usr/bin/gconftool                                                                                      
case "$HOUR" in                                                                                                   
    06|07)                                                                                                        
        $gconftool -t string -s /desktop/gnome/background/picture_filename ~/Bilder/DSC_0373.JPG                  
        ;;                                                                                                        
    08|09|10|11|12|13|14|15|16)                                                                                   
        $gconftool -t string -s /desktop/gnome/background/picture_filename ~/Bilder/DSC_1025.JPG                  
        ;;                                                                                                        
    17|18|19 )                                                                                                    
        $gconftool -t string -s /desktop/gnome/background/picture_filename ~/Bilder/DSC_0959.JPG                  
        ;;                                                                                                        
    *)                                                                                                            
        $gconftool -t string -s /desktop/gnome/background/picture_filename ~/Bilder/DSC_0776.JPG                  
        ;;                                                                                                        
esac                                                                                                              
 

Note: gconftool needs some environment variables of the user to run. These can be saved during login for later use

xdbus.sh
#!/bin/sh                                                                                                         
# Export the dbus session address on startup so it can be used by cron                                            
# use in cron /home/brb/.config/Xdbus;                                                                            
xdbus=$HOME/.config/Xdbus                                                                                         
touch $xdbus                                                                                                      
chmod 600 $xdbus                                                                                                  
env | grep DBUS_SESSION_BUS_ADDRESS > $xdbus                                                                      
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $xdbus                                                                  
# Export XAUTHORITY value on startup so it can be used by cron                                                    
env | grep XAUTHORITY >> $xdbus                                                                                   
echo 'export XAUTHORITY' >> $xdbus         

Add changedesktop to crontab, using crontab -e

# m h  dom mon dow   command                                                               
@reboot   /home/brb/bin/changedesktop.sh                                                   
0 * * * * /home/brb/bin/changedesktop.sh                                                   

~~LINKBACK~~

Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.