mala::home Davide “+mala” Eynard’s website

21Nov/061

Perl Hacks: Random Wallpaper

Time ago I was searching for a random wallpaper changer for Gnome, but I couldn't find one which was ok for me. These were the features I wanted:

  • it had to be as simple as a random wallpaper changer should be (you know, something like you click and it changes your wallpaper. Oh yes, randomly!)
  • it had to deal not just with the background image (stretching or shrinking it) but also with all the other background properties I'm used to set with Gnome
  • it didn't have to scan a whole directory and get all the pix inside it, but just to select the few images I liked most

Well, I decided to solve the problem myself with a quick and dirty Perl script: randomwp.pl. It just scans your backgrounds.xml file where your various backgrounds settings are saved, chooses one background randomly and then applies it. Quick? Yes. Dirty? Yes. But most of all working! :-)

How to install:

  • just make sure you have perl installed in your system with the XML::Simple package. For instance, run
    perl -MXML::Simple -e 'print "Everything ok.n"'

    on your command line and if the answer is "Everything ok" then... well, I suppose everything is ok! Otherwise, you should install XML::Simple package using CPAN. What? You don't know how to do it? Go and learn it! A hint?

    perl -MCPAN -e 'install XML::Simple'
  • download the script and modify it so it matches your home backgrounds.xml file location (a hint: start changing the $HOME path)
  • make sure you have at least two backgrounds configured within Gnome
  • run the script from the command line:
    perl randomwp.pl

If everything works fine, you can customize it in many ways:

  • make it run automatically at system startup or every few minutes
  • put a new icon on the panel and make it executable with one click
  • create many backgrounds.xml and pass them as parameters, so you have different wallpaper pools to choose from
  • unleash your imagination :)
Filed under: hacks, perl 1 Comment