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 lib "$FindBin::Bin/../lib";
66 my $VERSION = '$Revision: 1.10 $';
67 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
69 my $processes = new Proc::ProcessTable;
71 foreach my $process (@{$processes->table}) {
72 if ($process->cmndline =~ /setbg/ and
73 $process->pid != $$) {
74 kill 12, $process->pid;
80 $0 = "$FindBin::Script " . join ' ', @ARGV;
82 verbose "$FindBin::Script v$VERSION";
88 'usage' => sub { Usage },
89 'verbose' => sub { set_verbose },
90 'debug' => sub { set_debug },
92 'bgdir=s' => \@imgDir,
96 error "$_ is not a directory", 1 unless -d $_;
100 my $setbg = "gsettings";
101 my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://";
106 my @pics = `find "$_" -type f -name "*.jpg"`;
111 Usage "No images to display. Must specify -imgDir" unless @images;
113 sub SwitchWallPaper {
114 # We don't need to do anything here, just handle the interrupt and
115 # let the while loop continue.
116 debug 'SwitchWallPaper: Interrupt received';
119 $SIG{USR2} = \&SwitchWallPaper;
121 my $debugger = $DB::OUT;
123 EnterDaemonMode unless defined $DB::OUT;
126 my $image = $images[int (rand $#images)];
128 open my $log, '>', "$ENV{HOME}/.$FindBin::Script"
129 or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1;
131 display $image, $log;
133 my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null";