August 3rd, 2000

flagstaff coffee mug

(no subject)

Perl code du jour...

#!/usr/bin/perl

$delayMIN = 5;
$delayMAX = 30;

opendir DIR, "$ENV{HOME}/.wallpaper";
@images = grep !/^\.\.?$/, readdir DIR;
closedir DIR;

system "xv +noresetroot -root -quit $ENV{HOME}/.wallpaper/$images[int(rand scalar @images)] > /dev/null 2> /dev/null" and exit;

$delay = int(rand($delayMAX - $delayMIN)) + $delayMIN;

open AT, "|at now + $delay minutes > /dev/null 2> /dev/null";
print AT "DISPLAY=$ENV{DISPLAY}; export DISPLAY\n";
print AT "wallpaper.pl\n";
close AT;


It even bails in a friendly, quiet way if the display is unavailable; you can just kick it off in your .xinitrc or whatever.