Wallpaper Changer-Rotator


#! /bin/bash
ALIST=( `ls -w1 $WALLPAPERS` )
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
nitrogen --set-scaled --save $WALLPAPERS/${ALIST[$number]}


[Desktop Entry]
Comment=changes wallpaper

Create in your home directory a new directory named wallpaper. Put your desired wallpaper images in it, preferably the same size as your screen resolution. Be sure nitrogern is installed and place a copy of the shell script in the box on the upper-right into ~/bin and name it (by tawan from Crunchbang forum). Put a tick in the Make executable box that appears when right-clicking and following Properties>Permissions.

Launch nitrogen (see images above) and configure it to your situation. If you have lxsession (part of the lxde desktop) installed, then you probably have to edit it's autostart file, ~/.config/lxsession/LXDE/autostart, so that the line starting with "pcmanfm" is replaced by the following two lines:

    @pcmanfm --desktop-off --profile LXDE
    @ nitrogen --restore.

This passes the wallpaper control from pcmanfm to nitrogen after a re-boot.

Place a copy of the desktop file in the box on the lower-right in /usr/local/share/applications and name it changer.desktop. The Graphics category of the main dynamic menu should now have an entry changer, which when clicked will randomly select a new wallpaper from ~/wallpaper. From here you can add it to your panel in the usual way. You can also put an entry for changer in the Openbox menu using exec=~/bin/

There are various programs, for example, crontag and conky, that can be used to repeat a command in Linux. If Conky is installed, then the easiest way to use as the basis for a rotator is to use the exec-interval command present in Conky:

    ${execi x command},

where x is the interval in seconds that command is to be launched. So to get an automatic wallpaper rotation every 5 minutes (300 seconds), for example, put the following at the bottom of ~/.conkyrc:

    ${execi 300 ~/bin/}.

If crontag is installed, then to use a regular text editor, for example, geany, to set-up a crontag command, run the following command in terminal:

    EDITOR=geany crontab -e .

To run in 1 minute interval, put the following at the bottom of the text file that is launched:

    * * * * * DISPLAY=:0.0 ~/bin/ .

Next, hit the enter (return) key. Finally, save the file as usual. Be sure to hit the "enter" key before saving, or it will not be saved.

If you want the script to run every "m" minutes, replace the first asterisk by */m, where m can equal any of 2,3,4,5,6,10,12,15,20,30,60. If you want it to run every "h" hours, replace the second asterisk by */h, where h can equal any of 2,3,4,6,8,12,24. For additional crontab syntax, see nixCraft.

Below is an image of a Crunchbang desktop with the wallpaper changer icon on the far right of the lxde panel, the lxde menu at the far left, Conky on the right side, an open Openbox menu and the PhotoFiltre app open but rolled up.