Getting random interfacelift wallpaper

Just thought I'll share it – maybe somebody else will use it.

I'm using KDE 3.5, so the final “dcop …" command, simply sets the file as current wallpaper.

I also use 1680×1050 resolution – which you can probably guess from the code 🙂

#!/usr/bin/perl -w
use strict;
use English qw( -no_match_vars );
use WWW::Mechanize;
 
my $agent = WWW::Mechanize->new();
 
$agent->get("http://interfacelift.com/wallpaper_beta/downloads/random/widescreen/1680x1050/");
exit unless 200 == $agent->res->code;
 
my @links = $agent->find_all_links(
    'url_regex' => qr{1680x1050.jpg},
);
exit if 0 == scalar @links;
 
$agent->get( $links[ rand @links ] );
exit unless 200 == $agent->res->code;
 
my $username = getpwuid( $REAL_USER_ID );
my $filename = '/tmp/interfacelift.' . $username . '.jpg';
 
open my $fh, '>', $filename or exit;
binmode $fh;
print $fh $agent->res->decoded_content;
close $fh;
 
$ENV{"DISPLAY"} = ':0';
system( qw( /usr/bin/dcop kdesktop KBackgroundIface setWallpaper ), $filename, 4 );
 
exit;

Pretty simplistic, but it does the job. Now, I add this line to my crontab:

*/5  * * * * /home/depesz/bin/interfacelift.pl

And enjoy new, nice wallpaper every 5 minutes 🙂