
150
|
Chapter 6, GNOME Desktop Hacks
#45 Randomize Your GNOME Wallpaper
HACK
Unfortunately, a default option for performing this kind of randomized wall-
paper adjustment does not exist. Therefore, you will write a small script in
this hack to accomplish this. After a little time preparing the script, not only
will you have a randomized wallpaper set up, but also you will have a deeper
understanding of how GNOME can be scripted.
Selecting a Random Image
With a small bash script, it is possible to randomly select an image from a
directory and change the current GNOME wallpaper to that image. It’s easy
to forget just how powerful bash can be; more than just a simple command
shell,
bash has a whole host of features that make it well-suited for even
complex programming tasks.
To begin this hack, you need to have a directory full of wallpapers some-
where. Assume this directory is located at /home/foo/Images/Wallpapers/.
This script will take an image from that directory and set it as the current
wallpaper. Here’s the first part of the script:
#!/bin/bash
export DIR='/home/foo/Images/Wallpapers/'
export NUMBER=$RANDOM
export TOTAL=0
The first line is a standard piece of code that says which program should be
used to run the script (in this case bash). After this line is the location of the
directory containing your images, stored in the
$DIR variable for future use.
Next, you store a random number, which is