-   Linux - Newbie (
-   -   a script to change wallpaper (

sumeet inani 12-17-2009 11:29 PM

a script to change wallpaper
I came to know about 'crontab' command which allows you to schedule task at regular interval.
Then I found out 'gconftool-2' command to change desktop wallpaper in GNOME.
let us say I have my desired 100 wallpapers numbered 1.jpg to 100.jpg.
Now I want that script should increment location at every execution by cron daemon.
That is
script's main command will be

gconftool-2 -t str -g /desktop/gnome/background/picture_filename <file>

Is it possible ?
wouldn't that be great that wallpaper changes after every 5 minutes ?

~sHyLoCk~ 12-17-2009 11:42 PM

Yup it's possible. Even I wrote a friend of mine a script to automatically download and set wallpaper everyday using curl and put it in cron.daily.


sumeet inani 12-18-2009 01:46 AM

Can you tell how ?
I did not find it on

DrLove73 12-20-2009 05:08 AM

Well, first you need to design the way you want to go about.

My proposal:

Since you will want to add and/or delete background files you do not like, best would be to on each run create a list of currently existing files (ls *.jpg.... > existing.txt) and to keep list of already used files, where you would add a currently used file to that list (used.txt).

After creation of existing.txt, script compares it to used.txt to remove files from existing.txt that are also in used.txt, to avoid duplication. If all files have been used, empty the used.txt and set resulting list with all files from existing.txt.

Once you have prepared list of available files, either use the first one or use random number generator to select next file.

If gconftool-2 exits without errors, append that file to used.txt and exit.
I do not have time to create actual script, but implementation should not be to hard.

There is an option to create config file that will used several folders holding background files, desired way to select next file and maybe few other options.

catkin 12-20-2009 11:32 AM

Wallpaper Tray? Here are notes of installing version 0.4.6 on ubuntu 8.04

1.apt-get install wallpaper-tray
2.ln -s /usr/share/gnome/apps/Applications/wp_tray.desktop /usr/share/applications/ 
3.Configured ~./wallpapers as wallpaper directory
4.Set change to 120 mins.
5.Gnome Control Centre, Personal, Sessions, Add
        Name:  Start Wallpaper Tray
        Command:  /usr/bin/wallpaper-tray
        Comment:  Starts Wallpaper Tray
Alternatively create “~/.config/autostart/wallpaper-tray.desktop” with following content (first line is empty)

[Desktop Entry]
Name=No Name
Name[en_IN]=Start wallpaper-tray
Comment[en_IN]=Starts wallpaper-tray
Comment=Starts wallpaper-tray

isolatedsh33p 12-20-2009 12:32 PM

I also did create a bash script to change background every certain period. But the problem with it is that everytime the background changes, the CPU usage will increase sometimes 100% for a short while. So if the background changed while playing a game such as alien-arena, there's a slight performance down.

DrLove73 12-21-2009 01:56 AM

CentOS and Fedora do not have packages for anything similar. Truth to be told, Gnome is designed for small memory and CPU requirements. I used default wallpaper for CentOS for 3 years since my desktop is covered with applications 90% of the time.

catkin 12-21-2009 02:33 AM


Originally Posted by DrLove73 (Post 3799566)
Truth to be told, Gnome is designed for small memory and CPU requirements.

An interesting perspective; do you have any references to support it?

sumeet inani 12-21-2009 03:32 AM

My plan is that I will keep all my wallpapers in ~/wp numbered from 1 to 100.
After every 5 minutes script will run.
My aim is to represent file by %d.jpg so that it can be incremented at every run & variable type should be static.
After file variable becomes 100 we will rename it to 1 using 'if'.

how can i accomplish that ?

catkin 12-21-2009 04:07 AM

Any particular reason you don't want to use Wallpaper Tray to do the job?

sumeet inani 12-21-2009 04:51 AM

to catkin
I appreciate your detailed response.i will tag your post as 'software to change wall paper periodically' so that those who prefer software can find it easily.
But I like to use command & am also learning bash scripting.

isolatedsh33p 12-21-2009 06:11 AM

Huwm, I think I should be generous to share my script since I create it thanks to this thread :)
So here you go:


#Default values

#Wallpaper names
fnme=('wp1.jpg' 'wp2.jpg' 'wp3.jpg')

let bck=$fin-1

#Exit if the script is already running, just in case
#Got this part of script somewhere in this forum
if pidof -x $(basename $0) > /dev/null; then
  for p in $(pidof -x $(basename $0)); do
    if [ $p -ne $$ ]; then
      echo "Script $0 is already running: exiting"

#This is where the desktop wallpaper changes
for (( i=0;i<$fin;i++ )); do
    sleep $time #wait for $time second(s)
    gconftool-2 --type string --set /desktop/gnome/background/picture_filename $pictdir/${fnme[${i}]}
    if [ $i -eq $bck ]; then
        let i=-1

There's more thing can be done with this script, but for now, it's as simple as this. If you're playing a game, better kill this script so that it would not interrupt your game.

sumeet inani 12-21-2009 09:32 AM

to isolatedsh33p
In your case the script is running in background all the time ( when wallpaper is not being changed then it is sleeping ) while what I propose is that crontab will execute script to change wallpaper at regular intervals while in between two intervals script is not present in memory .

I think
i think that if variable's value is stored in file then its value will be static.
i mean
Suppose ~/int.txt initially contains 0
In our script
variable i takes its value from file int.txt & sets the wallpaper to ~/wp/0.jpg
Now increment i.
(i+1) >~/int.txt --note we are not appending value of i but overwriting int.txt file with next value.
In beginnning of script there will be condition
so we can have 99 wallpapers.
What do you say ?

I don't know much scripting so please help ?

catkin 12-21-2009 09:42 AM


Originally Posted by sumeet inani (Post 3799679)
But I like to use command & am also learning bash scripting.

That's cool :)

linus72 12-21-2009 09:47 AM

there was a early tinycore iso made by Master Okajima..

the background color changes at every boot, a function of his initrd or kernel?
I never took it apart but I thought it was neat that the background color would change at every boot on a read-only fs

oh I got it at my site:)

TC_OKAJIMA_20090514.ISO (11MB)

heres a usb version I made from updated tinycore iso and has extra apps too



Has apps like the others, but is based off TC-2.0rc1 hacked by the Honorable Mr Okajima!
and has a "Session-save" for CD-R ( ), also referenced here-
( )
The download also includes the "TC_OKAJIMA_20090514.iso" by Mr. Okajima.

play it on qemu,etc or put it on usb or hd and at each boot the color is different:)

All times are GMT -5. The time now is 08:36 PM.