#!/usr/bin/perl -w # by Darren Patterson # script to rotate bg in gnome 2 # easiest use is to run on startup or put in crontab use strict; use Image::Size; # minimum x and y dimension for image to stretch my $minx = 800; my $miny = 600; # location of backgrounds directory my $image_loc = "/home/darren/diamond/backup/My Documents/My Pictures"; # debug? my $debug = 0; ################################ # end of configurables ############################### # open and read the image location dir opendir (IMGS, "$image_loc") || die "can't opendir $image_loc: $!"; my @files = grep {/(jpg|gif|bmp|png)$/} readdir (IMGS); closedir IMGS; # perlmonks help on srand ;-) srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); my $random = (int(rand $#files + 1)); # get the appropriate file my $file = $files[$random]; # debug help if ($debug) {print "$random - $file\n";} # Get the size of the file my ($xsize, $ysize) = imgsize("$image_loc/$file"); # set the bg first (otherwise it resizes the previous img before changing) system("gconftool-2 --type=string --set /desktop/gnome/background/picture_filename \"$image_loc/$file\""); # if dimensions are less than 800 x 600, center, else stretch it if ( $xsize < $minx || $ysize < $miny) { system("gconftool-2 --type=string --set /desktop/gnome/background/picture_options centered"); } else { system("gconftool-2 --type=string --set /desktop/gnome/background/picture_options stretched"); } exit;