See here for unformatted version.
#!/bin/bash

PATH=$PATH:$HOME/bin/
export PATH


function run1() {
#    if `echo \`load|sed -n 's!.*2 min: *!!p'\` '>' 0.1 | bc` ; then
	#check to see whether computer is still in use. If it is, then there is a good chance the harddrive is still spun up, in which case it wont hurt to display a new image on the background

#	timesless1hour=`who -u | sort +5 | sed 's!\.!00:00!g' | sed -n 's!.*  *00:\(..\)  *[^ ]*$!\1!p'`
	timesless1hour=`who -u | sed 's!\.!00:00!g' | sort +5 | sed -n 's!.*  *00:\(..\)  *.*$!\1!p'`
        for i in $timesless1hour ; do
		if [ $i -le 30 ] ; then
			return 0
		fi
	done
	return 1
}

function run2() {
    load=`awk '{print $1}' /proc/loadavg`
    if `echo "$load" '<' 0.4 | bc`  ; then
              #if too busy, we are likely to play havok with swapping
	return 0
    fi
    return 1
}


if [ -e /var/tmp/background.pid ] ; then
    kill `cat /var/tmp/background.pid`
fi

echo $$ > /var/tmp/background.pid

picknewbackground.sh  #first off, before anything, make sure we have a background
sleep 600


while : ; do 
    if run1 ; then 
        if run2 ; then
           picknewbackground.sh
        fi
        sleep 600 
    else
        sleep 3600
    fi
done