Hi monks. I've written this simple script that parses the ~/.gnome2/backgrounds.xml file, picks a random wallpaper and sets it as default using the GConf interface (obviously only for the GNOME desktop environment).

Update: corrected off-by-one error thank to jwkrahn.

#!/usr/bin/perl # Gnome random wallpaper picker. # # Copyright (C) 2010 Alessandro Ghedini <al3xbio@gmail.com> # -------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Alessandro Ghedini wrote this file. As long as you retain this # notice you can do whatever you want with this stuff. If we # meet some day, and you think this stuff is worth it, you can # buy me a beer in return. # -------------------------------------------------------------- use Gnome2::GConf; use XML::Simple; use strict; use warnings; my $client = Gnome2::GConf::Client -> get_default; my $bg_file = $ENV{'HOME'}.'/.gnome2/backgrounds.xml'; my $key = '/desktop/gnome/background/picture_filename'; open BG, $bg_file or die $!; my $xml_data = join '', <BG>; close BG; my $xml = XMLin($xml_data); my @wallpapers; while (my ($key, $value) = each(%{$xml -> {'wallpaper'}})){ push @wallpapers, $key if $value -> {'deleted'} eq 'false'; } my $name = $wallpapers[rand(@wallpapers)]; my $selected = $xml -> {'wallpaper'} -> {$name}; print "Selected Wallpaper: $name\n"; $client -> set($key, {type => 'string', value => $selected -> {'filename'}}); __END__ =head1 NAME gnome-random-wallpaper.pl - Gnome random wallpaper picker. =head1 USAGE gnome-random-wallpaper.pl =head1 DESCRIPTION This script simply reads the ~/.gnome2/backgrounds.xml file, where are stored the default wallpapers for Gnome, randomly selects one of them, and sets it using the GConf interface. =cut

The usage is very simple, just run it without any arguments.

Alex's Log - http://alexlog.co.cc

In reply to GNOME Random Wallpaper Picker by alexbio

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.