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 # 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

In reply to (code) WindowMaker background image rotater by ybiC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.