X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=bin%2Fsetbg;h=39ce45bf53eb5506c22ed33ebf1984a433595485;hb=ea8b63b8850251c086194f92a1b2a0348ef22c7b;hp=ddfa756642f65d401c446feda3ef4ee68a695f7e;hpb=c18e95513620e98cb01133d8911163fb7f7d5c09;p=clearscm.git diff --git a/bin/setbg b/bin/setbg index ddfa756..39ce45b 100755 --- a/bin/setbg +++ b/bin/setbg @@ -57,6 +57,7 @@ use warnings; use FindBin; use Getopt::Long; use Proc::ProcessTable; +use CGI qw/:standard/; use lib "$FindBin::Bin/../lib"; @@ -82,24 +83,34 @@ $0 = "$FindBin::Script " . join ' ', @ARGV; verbose "$FindBin::Script v$VERSION"; my $sleep = 60 * 60; -my $imgDir = $ENV{SETBG_DIR} ? $ENV{SETBG_DIR} : '/web/Pictures'; +my @imgDir; GetOptions ( - 'usage' => sub { Usage }, - 'verbose' => sub { set_verbose }, - 'debug' => sub { set_debug }, - 'sleep=i' => \$sleep, - 'bgdir=s' => \$imgDir, + 'usage' => sub { Usage }, + 'verbose' => sub { set_verbose }, + 'debug' => sub { set_debug }, + 'sleep=i' => \$sleep, + 'bgdir=s' => \@imgDir, ) || Usage; -error "$imgDir is not a directory", 1 unless -d $imgDir; +foreach (@imgDir) { + error "$_ is not a directory", 1 unless -d $_; +} # foreach # Using gsettings -my $setbg = "gsettings"; +my $setbg = "gsettings"; my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://"; -chomp (my @images = `find $imgDir -type f -name "*.jpg"`); +my @images; + +foreach (@imgDir) { + my @pics = `find "$_" -type f -name "*.jpg"`; + chomp @pics; + push @images, @pics; +} # foreach +Usage "No images to display. Must specify -imgDir" unless @images; + sub SwitchWallPaper { # We don't need to do anything here, just handle the interrupt and # let the while loop continue. @@ -113,7 +124,7 @@ my $debugger = $DB::OUT; EnterDaemonMode unless defined $DB::OUT; while () { - my $image = $images[int (rand $#images)]; + my $image = escapeHTML ($images[int (rand $#images)]); open my $log, '>', "$ENV{HOME}/.$FindBin::Script" or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1; @@ -122,8 +133,14 @@ while () { my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null"; - `$cmd`; + my @output = `$cmd`; + if ($? != 0) { + display "ERROR Trying to set background - command used \"$cmd\"", $log; + display "Output:"; + display join "\n", @output, $log; + } # if + close $log; sleep $sleep;