Kevin Locke's Homepage

RotateBG: A script to rotate the desktop wallpaper (background)


RotateBG is a shell script which builds a list of files from the files and directories (searched recursively) listed on the command-line (or from stdin if none are listed). It then sorts this list and changes the current background to the next in the list, or changes to the first in the list if the current background is not in the list, or to a random file if the -r switch is specified.

RotateBG is based on grotbckgd created by Damien Merenne. Unfortunately, when I last contacted Mr. Merenne he did not have access to that website any longer and therefore could not post patches to the program. Since then I have made several changes to the program to the point that the similarity to the original program is somewhat vague and I would feel bad sending a patch this large, which means that it is time to post it here.


  1. Not Bash-dependent (should run in any POSIX-compatible shell)
  2. Handles filenames with spaces (and all characters except '\n' and '#')
  3. The command to set the background can be specified on the command-line which allows it to work with any window manager.
  4. In combination with a periodic scheduler (like cron) RotateBG can be used to periodically change the desktop background, either randomly or in progression.

Development Status

Stable. I don't have any other features planned and I haven't come across any bugs for a while. Bugs and proposed improvements would be considered.


Expat Style - The original author requires that the copyright statement remain intact, no additional conditions have been added.



  1. Download it, possibly into your PATH (e.g. ~/bin)
  2. Make it executable (e.g. chmod +x
  3. Run the script to change your background (use ./ -h to see the usage information).
  4. Optionally, schedule it to run periodically. This can be accomplished by adding it to your crontab by typing crontab -e and adding a line like the following to your crontab:
    */5 * * * * $HOME/bin/ -r $HOME/wallpapers
    which will run every 5 minutes and set the wallpaper to a random image in a subdirectory of $HOME/wallpapers

Example Usage


It is possible to change the default values by editing the script, however this should be unnecessary. Determining the proper command-line arguments should be all of the configuration that is required.

Known Bugs

The script should have improved default behavior, such as testing for more alternatives to set the desktop wallpaper than gconftool if none is specified on the command-line. Suggestions for appropriate commands would be appreciated.