#!/bin/bash

dir="$HOME/GNUstep/Library/WindowMaker/Backgrounds/cron/"
last=`<"$HOME/.switch-wallpaper"`
[ "$last" == "" ] && last="there-is-no-last-image"
files="`find $dir | grep -v "$last"`"
max="`wc -l <<< "$files"`"
arr=($files)
item=`expr $RANDOM % \( $max - 1 \) + 1`
new="${arr[$item]}"
echo $new > "$HOME/.switch-wallpaper"
DISPLAY=:0 nice wmsetbg -s -u "$new"

