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";
67 my $VERSION = '$Revision: 1.10 $';
68 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
70 my $processes = new Proc::ProcessTable;
72 foreach my $process (@{$processes->table}) {
73 if ($process->cmndline =~ /setbg/ and
74 $process->pid != $$) {
75 kill 12, $process->pid;
81 $0 = "$FindBin::Script " . join ' ', @ARGV;
83 verbose "$FindBin::Script v$VERSION";
89 'usage' => sub { Usage },
90 'verbose' => sub { set_verbose },
91 'debug' => sub { set_debug },
93 'bgdir=s' => \@imgDir,
97 error "$_ is not a directory", 1 unless -d $_;
101 my $setbg = "gsettings";
102 my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://";
107 my @pics = `find "$_" -type f -name "*.jpg"`;
112 Usage "No images to display. Must specify -imgDir" unless @images;
114 sub SwitchWallPaper {
115 # We don't need to do anything here, just handle the interrupt and
116 # let the while loop continue.
117 debug 'SwitchWallPaper: Interrupt received';
120 $SIG{USR2} = \&SwitchWallPaper;
122 my $debugger = $DB::OUT;
124 EnterDaemonMode unless defined $DB::OUT;
127 my $image = escapeHTML ($images[int (rand $#images)]);
129 open my $log, '>', "$ENV{HOME}/.$FindBin::Script"
130 or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1;
132 display $image, $log;
134 my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null";
139 display "ERROR Trying to set background - command used \"$cmd\"", $log;
141 display join "\n", @output, $log;