#!/bin/bash

if ! [ $1 ];then
	echo "Usage $0 <DIR>"
	exit
fi
if [ ! -d $1 ];then
	echo "Usage $0 <DIR>"
	exit
fi

FILE=$(find $1 -type f | shuf -n 1);

### gnome2 ##############################
key="/desktop/gnome/background/picture_filename"
gconftool-2 -t string -s $key $FILE || gconftool -t string -s $key $FILE
### gnome3 ##############################
key="/org/gnome/desktop/background/picture-uri"
key2="org.gnome.desktop.background picture-uri"
dconf write $key "'$FILE'"
gsettings set $key2 "'file://$FILE'"
### MATE ################################
key="org.mate.background picture-filename"
key2="/org/mate/desktop/background/picture-filename"
gsettings set $key "'$FILE'"
dconf write $key2 "'$FILE'"
### XFCE ################################
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s $FILE
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image -s $FILE
### LXDE ################################
pcmanfm -w $FILE
