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.
- Not Bash-dependent (should run in any POSIX-compatible shell)
- Handles filenames with spaces (and all characters except '\n' and '#')
- The command to set the background can be specified on the command-line which allows it to work with any window manager.
- In combination with a periodic scheduler (like cron) RotateBG can be used to periodically change the desktop background, either randomly or in progression.
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.
- Bash-like shell (dash, posh, sh, etc.)
- Unix core utilities (awk, sed, grep)
- Download it, possibly into your PATH (e.g. ~/bin)
- Make it executable (e.g.
chmod +x rotatebg.sh)
- Run the script to change your background (use
./rotatebg.sh -hto see the usage information).
- Optionally, schedule it to run periodically. This can be accomplished
by adding it to your crontab by typing
crontab -eand adding a line like the following to your crontab:
*/5 * * * * $HOME/bin/rotatebg.sh -r $HOME/wallpapers
which will run rotatebg.sh every 5 minutes and set the wallpaper to a random image in a subdirectory of $HOME/wallpapers
./rotatebg.sh ~/wallpaper- Set the desktop wallpaper to the next image from a subdirectory of ~/wallpaper.
./rotatebg.sh -r -t jpg,png,gif,bmp ~/wallpaper- Set the desktop wallpaper to a random image with a .jpg .png .gif or .bmp extension from a subdirectory of ~/wallpaper.
./rotatebg.sh -t xbm --setbgcmd "xsetroot -bitmap" -f ~/.bgimage ~/wallpaper- Set the desktop wallpaper using xsetroot to an X Bitmap (xbm) image in a subdirectory of ~/wallpaper and keep track of the current wallpaper in the file ~/.bgimage (to determine which image is next, if this option were not specified -r would be assumed).
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.
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.