Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

(code) WindowMaker background image rotater

by ybiC (Prior)
on Mar 14, 2004 at 23:05 UTC ( #336558=snippet: print w/replies, xml ) Need Help??
Description: Randomly rotate WindowMaker background image.   For Debian use, place script in /etc/init.d/ directory, and symlink from /etc/rcS.d/, or else call the script from cron reboot jobs.

Woof - four months is too long to go between perlings.   8^P

As always, critique is welcome and requested.

Update: Thanks to Corion, chip, theorbtwo, and dws for CB help in getting my brain back into perl mode with this.

#!/usr/bin/perl5.8.0 -w

# pod at tail

use strict;
use Cwd;
# use Module::Versions::Report;

my $dir      = '/usr/share/WindowMaker/Backgrounds';
my $linkname = '00rotation_image';
my $randfile = '';

print "Rotating WindowMaker background image... ";
chdir $dir or die "$!\n";
$randfile = RandFile($dir) until (-f $randfile && -B _);

if (-e $linkname){
  die "$!\n" unless (-l $linkname && -w _);
  unlink $linkname or die "$!\n";
symlink $randfile, $linkname or die "$!\n";
print "done.\n";

sub RandFile {
  opendir F, $_[0] or die "$!\n";
  my @F = grep { /^\w.*/ } readdir F;
  return $F[rand @F];

=head1 TITLE


 Place script in /etc/init.d directory,
 symlink from /etc/rcS.d,
 point WindowMaker background image to $linkname

 Or call script from cron reboot job


 Randomly rotate WindowMaker background images.

=head1 TODO

 Check for -f and -B from within &RandFile()

=head1 UPDATE

 2004-03-15   12:35 CST
   Test against Perl 5.6.1
   Revise logic for checks - exists, writable, symlink
   Trivial code correction and pod tweaks
   Post to PM Snippets
   Rewrite as small script instead of one-liner

   Initial working code

=head1 TESTED

 Debian                    3.0r2
 Perl                      5.8.0  5.6.1
 strict                    1.02   1.01
 warnings                  1.00
 Cwd                       2.06   2.04
 Modules::Versions::Report 1.02

=head1 BUGS

 None that I know of

=head1 CREDITS

 Thanks to Corion, chip, theorbtwo, and dws
 for CB help in getting my brain back into perl mode with this.
 And to some guy named vroom.

 perl -e 'opendir F,".";@F=readdir F;print $F[rand @F];'
 ls -l | perl -e '@F=<>;print $F[rand @F];'

=head1 AUTHOR


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://336558]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-10-22 23:34 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (86 votes). Check out past polls.