Skip to Main Content
Linux Desktop Hacks
book

Linux Desktop Hacks

by Nicholas Petreley, Jono Bacon
March 2005
Beginner to intermediate content levelBeginner to intermediate
342 pages
15h 55m
English
O'Reilly Media, Inc.
Content preview from Linux Desktop Hacks
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Server Hacks, Volume Two

Linux Server Hacks, Volume Two

William von Hagen, Brian K. Jones
Introducing Linux Distros

Introducing Linux Distros

Jose Dieguez Castro

Publisher Resources

ISBN: 0596009119Supplemental ContentCatalog PageErrata