CUFP
ybiC
snippet
<div class="Description">Randomly rotate <a href="http://www.windowmaker.org/">WindowMaker</a> background image. For <a href="http://www.debian.org/">Debian</a> use, place script in <tt>/etc/init.d/</tt> directory, and symlink from <tt>/etc/rcS.d/</tt>, or else call the script from cron reboot jobs.
<p>
Woof - four months is <i>too long</i> to go between perlings. 8^P
</p>
<p>
As always, critique is welcome and requested.
</p>
<p>
<b>Update: </b> Thanks to [Corion], [chip], [theorbtwo], and [dws] for CB help in getting my brain back into perl mode with this.
</p></div>
<CODE>#!/usr/bin/perl5.8.0 -w
# wmb_rotate.pl
# 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
wmb_rotate.pl
=head1 SYNOPSIS
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
=head1 DESCRIPTION
Randomly rotate WindowMaker background images.
=head1 TODO
Check for -f and -B from within &RandFile()
...profit!
=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
2004-03-13
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
ybiC
=cut
</CODE>