5 =head1 NAME $RCSfile: setbg,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Fri Mar 18 01:14:38 PST 2005
27 $Date: 2012/11/09 15:31:30 $
33 Usage: setbg [-u|sage] [-ve|rbose] [-d|ebug] [-s|leep <n>] [-bgdir <bgdir>]
37 -u|sage: Displays this usage
39 -d|ebug: Output debug messages
41 -s|leep: Number of minutes to sleep between setting the background
43 -b|gdir: Directory to scan for images (Default: /web/Pictures)
47 This script sets the background image randomly based on images $imgDir. Note
48 if this script is run again it senses that it was previously run and sends the
49 previous script a SIGUSR2 which the script intrprets as "Change the background
59 use Proc::ProcessTable;
61 use CGI qw/:standard/;
63 use lib "$FindBin::Bin/../lib";
69 my $VERSION = '$Revision: 1.10 $';
70 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
72 my $processes = new Proc::ProcessTable;
75 foreach my $process (@{$processes->table}) {
76 if ($process->cmndline =~ /setbg/ and
77 $process->pid != $$) {
78 kill 12, $process->pid;
88 my @pics = `find "$_" -type f -name "*.jpg"`;
97 $0 = "$FindBin::Script " . join ' ', @ARGV;
99 verbose "$FindBin::Script v$VERSION";
104 'usage' => sub { Usage },
105 'verbose' => sub { set_verbose },
106 'debug' => sub { set_debug },
107 'sleep=i' => \$sleep,
108 'bgdir=s' => \@imgDirs,
111 for (my $i = 0; $i < scalar @imgDirs; $i++) {
112 error "$imgDirs[$i] is not a directory", 1 unless -d $imgDirs[$i];
114 $imgDirs[$i] = File::Spec->rel2abs ($imgDirs[$i]);
118 my $setbg = "gsettings";
119 my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://";
121 my @images = fillPictures;
123 Usage "No images to display. Must specify -bgdir" unless @images;
125 sub SwitchWallPaper {
126 # We don't need to do anything here, just handle the interrupt and
127 # let the while loop continue.
128 debug 'SwitchWallPaper: Interrupt received';
131 $SIG{USR2} = \&SwitchWallPaper;
132 $SIG{USR1} = \&fillPictures;
134 my $debugger = $DB::OUT;
137 EnterDaemonMode unless defined $DB::OUT;
140 my $image = escapeHTML ($images[int (rand $#images)]);
142 open my $log, '>', "$ENV{HOME}/.$FindBin::Script"
143 or error "Unable to open $ENV{HOME}/.$FindBin::Script for writing - $!", 1;
145 display $image, $log;
147 my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null";
152 display "ERROR Trying to set background - command used \"$cmd\"", $log;
154 display join "\n", @output, $log;
164 @images = fillPictures;