Sunday, April 22, 2007

[BLUG] random wallpaper in Ubuntu

I wish Gnome had an option to easily set it to randomly select a new wallpaper every x minutes, but, alas, it doesn't.  I'm sure this is nothing new to most of you, but it took me a little while to figure this one out, so I thought I'd share in case anybody didn't know.  And if you know of a better way to do this, please let me know!

1.  sudo gedit

2.  copy this, but replace /home/ben/wallpaper/ with the directory where you have your wallpapers:

#!/bin/bash

# Set your folder with the pics
picsfolder="/home/ben/wallpaper/"

# Go to your folder with the pics
cd "$picsfolder"

# Get the name of a random file
randomfile=`ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p`

# start of gconftool command and set the desktop
gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomfile"

3.  save as changewallpaper.sh in /bin

4.  'sudo chmod +x /bin/changewallpaper.sh'

5.  'crontab -e'

6.  add these lines: 
*/15 * * * * changewallpaper.sh
@reboot changewallpaper.sh

7.  save and exit

And that should be it.  At least it was for me.  That changes the wallpaper every boot and every 15 minutes.  I also added a custom application launcher to my panel with the command '/bin/changewallpaper.sh' and I can click that button to randomly select a new wallpaper if I don't like the current one.   Oh, and I like http://interfacelift.com/ for good wallapapers.  Also, I didn't write that little script, I stole it from this thread:  http://ubuntuforums.org/showthread.php?t=329164&highlight=random+wallpaper

ben








Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.

No comments: