Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

GNOME Random Wallpaper Picker

by alexbio (Monk)
on Jun 29, 2010 at 19:15 UTC ( #847188=CUFP: print w/replies, xml ) Need Help??

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 <> # -------------------------------------------------------------- # "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 picker. =head1 USAGE =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 -

Replies are listed 'Best First'.
Re: GNOME Random Wallpaper Picker
by jwkrahn (Monsignor) on Jun 29, 2010 at 20:31 UTC

    You have an off-by-one error.

    my $name = $wallpapers[rand($#wallpapers)];

    Should be:

    my $name = $wallpapers[rand(@wallpapers)];

      Thank you, I've corrected the code.

      Alex's Log -
Re: GNOME Random Wallpaper Picker
by ambrus (Abbot) on Jul 04, 2010 at 15:22 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://847188]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-03-22 14:46 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (277 votes). Check out past polls.