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";
85 my $imgDir = $ENV{SETBG_DIR} ? $ENV{SETBG_DIR} : '/web/Pictures';
88 'usage' => sub { Usage },
89 'verbose' => sub { set_verbose },
90 'debug' => sub { set_debug },
92 'bgdir=s' => \$imgDir,
95 error "$imgDir is not a directory", 1 unless -d $imgDir;
98 my $setbg = "gsettings";
99 my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://";
101 chomp (my @images = `find $imgDir -type f -name "*.jpg"`);
103 sub SwitchWallPaper {
104 # We don't need to do anything here, just handle the interrupt and
105 # let the while loop continue.
106 debug 'SwitchWallPaper: Interrupt received';
109 $SIG{USR2} = \&SwitchWallPaper;
111 my $debugger = $DB::OUT;
113 EnterDaemonMode unless defined $DB::OUT;
116 my $image = $images[int (rand $#images)];
118 open my $log, '>', "$ENV{HOME}/.$FindBin::Script"
119 or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1;
121 display "Current background: $image", $log;
123 my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null";