X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;ds=inline;f=bin%2Fsetbg;h=39ce45bf53eb5506c22ed33ebf1984a433595485;hb=78865a3b920fa9681f16285ae96f2ffe9af0d12f;hp=777f6329b12ae5ca87a14de5aa41c71b5820e8dd;hpb=020a4a5ea2be725b155cae3a2cadc9aba3911b9b;p=clearscm.git diff --git a/bin/setbg b/bin/setbg index 777f632..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,17 +124,23 @@ 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; - display "Current background: $image", $log; + display $image, $log; 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;