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;
60 use CGI qw/:standard/;
62 use lib "$FindBin::Bin/../lib";
68 my $VERSION = '$Revision: 1.10 $';
69 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
71 my $processes = new Proc::ProcessTable;
74 foreach my $process (@{$processes->table}) {
75 if ($process->cmndline =~ /setbg/ and
76 $process->pid != $$) {
77 kill 12, $process->pid;
87 my @pics = `find "$_" -type f -name "*.jpg"`;
96 $0 = "$FindBin::Script " . join ' ', @ARGV;
98 verbose "$FindBin::Script v$VERSION";
103 'usage' => sub { Usage },
104 'verbose' => sub { set_verbose },
105 'debug' => sub { set_debug },
106 'sleep=i' => \$sleep,
107 'bgdir=s' => \@imgDirs,
111 error "$_ is not a directory", 1 unless -d $_;
115 my $setbg = "gsettings";
116 my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://";
118 my @images = fillPictures;
120 Usage "No images to display. Must specify -imgDir" unless @images;
122 sub SwitchWallPaper {
123 # We don't need to do anything here, just handle the interrupt and
124 # let the while loop continue.
125 debug 'SwitchWallPaper: Interrupt received';
128 $SIG{USR2} = \&SwitchWallPaper;
129 $SIG{USR1} = \&fillPictures;
131 my $debugger = $DB::OUT;
134 EnterDaemonMode unless defined $DB::OUT;
137 my $image = escapeHTML ($images[int (rand $#images)]);
139 open my $log, '>', "$ENV{HOME}/.$FindBin::Script"
140 or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1;
142 display $image, $log;
144 my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null";
149 display "ERROR Trying to set background - command used \"$cmd\"", $log;
151 display join "\n", @output, $log;
161 @images = fillPictures;