#!/usr/bin/perl use File::Find; #to get all files under mainDir use Getopt::Std; # command line processing getopts("w:d:")|| die "Invalid argument\n"; if ($opt_w =~ /\D/) { die "w is not a digit";} @images = (); if ( $opt_w ) { $workspace = $opt_w-1; } sub process_file{ $filename = $File::Find::name; if ( -f $filename ){ push(@images, $filename); } } if ( $opt_d ) { $basedir = $opt_d; } else{ $basedir = "/usr/local/share/Backgrounds"; } find(\&process_file, $basedir); srand; $index=int(rand(@images)); if ($opt_w){ print "\n On workspace $opt_w, the background image is now @images[$index] \n"; exec '/usr/local/wm/bin/wmsetbg','-display',':0.0','-a',' ','-u',' ','-w',"$workspace",' ', $images[$index]; } else{ print "\n The background image of the root window is @images[$index] \n"; exec '/usr/local/wm/bin/wmsetbg','-display',':0.0','-a',' ','-u',' ', $images[$index]; }