#!/usr/bin/perl
#Usage: chbg.pl -b /opt/wallpaper/ -t 3 -m
#Read it like: Change the background every 3 minutes and get a random background
#from /opt/wallpaper
use Getopt::Std;
getopts('b:t:m', \my %opt);
die if !$opt{t} or !$opt{b};
opendir DIRECTORY, $opt{b};
@images = readdir DIRECTORY;
closedir DIRECTORY;
$ENV{DISPLAY} = ":0.0";
while(1){
	system('/usr/bin/xsetbg', "$opt{b}/$images[rand($#images-2)+2]");
	if($opt{m}){ sleep($opt{t} * 60); } else{ sleep($opt{t}) } ;
}	
