How do I automatically cycle through backgrounds in Ubuntu 9.10?

2

1

I heard this is a new feature in 9.10, but I can't figure out how to use it. If it isn't a default feature, what's the best way to go about setting it up?

I prefer to have something invisible--no panel applets, unless the panel icon can be turned off.

Matthew

Posted 2009-11-12T16:23:45.927

Reputation: 11 686

Answers

3

You can do this without installing additional software. Simply use gconftool with a little shell script trickery (untested):

#!/bin/bash

while [ 1 ]
do
find /path/to/wallpapers/folder -type f > ~/walls.txt
count=$(cat ~/walls.txt | wc -l)
    for files in $(seq $count)
    do
        file=$(cat ~/walls.txt  | head -n $files | tail -n 1)
        gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$file"
        sleep 300 # wait 5 minutes before changing again
    done
done

you'll need to change the /path/to/wallpaper/folder accordingly. This will go through every image in the folder, changing every 5 minutes. Once they've all been used it will start at the beginning again, and regenerate the file containing the names of the wallpapers to include any new wallpapers.

John T

Posted 2009-11-12T16:23:45.927

Reputation: 149 037

Does the script actually run without errors? you'll have to update me. – John T – 2009-12-21T18:59:57.683

Yep, thanks! Obviously I had to change the path, but other than that...one important note: you must run this script as yourself. Don't do sudo or anything, or it won't change the background (I think it changes the super user's background instead).

Is there any way to do this without creating a new file? It works fine, it just seems kind of messy to do it this way. – Matthew – 2009-12-21T19:20:22.603

Also, you might want to tweak the script to start on your current background, instead of restarting the cycle every time the script is run. I might play around with this later today and try to improve it. – Matthew – 2009-12-21T19:22:08.420

1Thanks for the clarification, that's pretty awesome. You can use a different method other than flat files, but that would involve another query on the directory, and I tried to stick with the UNIX tradition of using flat files for mostly everything. Depending on how many images there are it could make a noticeable "hiccup" in your activities, as simple I/O on a flat file wouldn't be as noticeable. For that reason I only did it once after every wallpaper has cycled. gconftool will change the current users settings like you said, thats why running as sudo will not work. – John T – 2009-12-21T19:34:50.623

1As for starting on the current background, after the file is created you could use cat -n to prepend line numbers, then grep the current value from gconftool, and yank the line number from the beginning then start from there. Multiple ways to skin a cat, keep me updated on your improvements, If I have time I may code a daemon to do this. – John T – 2009-12-21T19:37:16.343

2

Here's a quick shell script and cron job that will change to a random wallpaper every hour.

/home/aolsen/bin/wallpaper.sh

BKG_DIR="/home/aolsen/BKG/"
FILE="${BKG_DIR}$(ls "${BKG_DIR}" |sort -R |head -n1)" 
gconftool-2 --type string --set /desktop/gnome/background/picture_filename "${FILE}"

crontab -e

0 * * * * /home/aolsen/bin/wallpaper.sh

Change the 0 to */5 to make it switch every 5 minutes.

user24940

Posted 2009-11-12T16:23:45.927

Reputation: 21

1

From here

Configure Desktop gives the option of a slideshow composed of any backgrounds you choose.

.

you can user wallpaper-tray is nice and easy. The options are very similar to kde's desktop background options.

joe

Posted 2009-11-12T16:23:45.927

Reputation: 11 615

I'm not sure what "Configure Desktop" is. It's not in a default Ubuntu 9.10 intall, and it's not in the repositories. wallpaper-tray and the similar "Desktop Drapes" are panel applets, I'd rather have something invisible (I'll edit my question to reflect this). – Matthew – 2009-11-12T16:38:06.910