#!/usr/bin/perl # By PJ Balsley & Nick Berry # Purpose: Change Gnome desktop wallpaper. # Put in your crontab, to change once a day. # 0 0 * * * ~/bin/wp-changer.pl # Version 0.4 use strict; #- Values -# my $debug = "0"; ## 0 = off, 1 = on my $gnome_file = "/desktop/gnome/background/picture_filename"; my $wallpaper = "$ENV{'HOME'}/Documents/My-stuff/Wallpaper"; #- Execption directories -# my @execption = ("800x600", "1024x768", "1280x800", "1600x1200", "2560x1024", "1280x1024" ); #- Generate execpt string -# my $expect = undef; my $ex = undef; foreach $ex (@execption) { chomp($ex); if($expect) { $expect .= " -a \! -wholename '*$ex*'"; } else { $expect = "\! -wholename '*$ex*'"; } } #- Find background images -# my @ls = `find $wallpaper $expect -type f -print`; if ($debug == "1") { print "find $wallpaper $expect -type f -print\n"; } #- Pick one randomly -# my $randfile = &random(@ls); my $currentfile = `grep \"$randfile\" $ENV{"HOME"}/.gconf/desktop/gnome/background/\%gconf.xml`; while ($currentfile) { if ($debug == "1") { print "Randomize matched the same wallpaper ($randfile), randomizing again.\n"; } $randfile = &random(@ls); $currentfile = `grep \"$randfile\" $ENV{"HOME"}/.gconf/desktop/gnome/background/\%gconf.xml`; } #- Change the Gnome background value -# system("gconftool-2 -t string -s $gnome_file \"$randfile\""); if ($debug == "1") { print "gconftool-2 -t string -s $gnome_file \"$randfile\"\n"; } #- Sub Routines -# #----------------# sub random(@ls) { #- randomly pick a picture. -# my $randnum = rand(@ls); $randnum = int $randnum; my $randfile = $ls[$randnum]; chomp($randfile); return $randfile; }