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 🙂

7 thoughts on “Getting random interfacelift wallpaper”

  1. ln -sf /home/depesz/some_important_file /tmp/interfacelift.depesz.jpg

    And you’re toast.

  2. @Tomasz Ostrowski:
    well, there are 2 possible ways:
    1. i’m braindead and do it myself
    2. somebody has access to my machine and runs it to “toast” me.

    If it’s #1: – well if i’m braindead, then I definitely by punished by not thinking.
    If it’s #2: – if somebody has privileges to do something like this on my laptop – well, he can do much worse things than this.

    So, I don’t quite understand your comment. Yes, I’d be toast, but it’s either unlikely, understandable punishment for not using brain functions, or extremely complicated way to do me some harm byt somebody who got shell access to my laptop. can’t imagine such situation.

  3. It’s not about you. You have published your script, so somebody can use it on his or work computer, which can be shared.

    Also it does not hurt to write even basic, fun scripts like this secure. It is not hard and it is a training.

  4. Here’s the script I use to download and apply a random wallpaper from interface lift on my HTPC connected to an HDTV

    Running Ubuntu 10.04 with Ubuntu Desktop (GNOME)

    #!/bin/bash
    wget -U "Mozilla/5.0" -O - http://interfacelift.com/wallpaper_beta/downloads/random/hdtv/ | \
        grep download.png | \
        sed 's/^\s*<a href="\([^"]\+\)" rel="nofollow"><[^>]\+download.*$/http:\/\/www.interfacelift.com\1/' | \
        head -n 1 | \
        wget -U "Mozilla/5.0" -i - -O wallpaper.jpg.tmp
    mv wallpaper.jpg.tmp wallpaper.jpg
    touch wallpaper.jpg

    then i just set wallpaper.jpg (which ends up being in my home directory when running the script as a cron job) to be my wallpaper.

    The touch part is important to make GNOME update the wallpaper. And the -U “Mozilla/5.0” is also essential to be able to access interfacelift (they seem to be filtering content by browser… or lack thereof. Probably to prevent scripts like these)

    The script essentially gets the first wallpaper from the Random Wallpaper page on interfacelift for 1080 resolution monitor. So just change the first URL to what you need.

  5. Adding -q flag to both wget commands will prevent a lot of useless stderr output from getting sent to system mail (when using script as cron job). This, however, also suppresses actual error messages

Comments are closed.