Previous Page
PCLinuxOS Magazine
Article List
Next Page

A Wallpaper Slideshow For Any Desktop

by Paul Arnote (parnote)

All of us like to change our desktop wallpaper from time to time. Some like to change it very frequently, like every 30 minute or every three hours or every day. Judging by some posts in the PCLinuxOS forum, there is a good number of folks who want to be able have their wallpaper change automatically after a predetermined amount of time, creating a wallpaper slideshow, of sorts, on their desktop.

A couple of months ago, I wrote an article on how to use Xfce's built in wallpaper slideshow utility, along with a couple of Thunar custom actions to allow you to set it up. In recent months, I've been seeing a number of users clamoring for such a utility under the Mate and LXDE desktops. Reusing some of the code from the NatGeo and Bing wallpaper scripts, I've managed to come up with a script that creates a wallpaper slideshow not only on Xfce, but also on KDE, Mate, e17 and LXDE.

Yes, there are other "wallpaper slideshow" programs in the PCLinuxOS repository. However, some of them are specific to certain desktop environments. Others are just clunky to use, at best. My goal was to create something that works across all of the desktop environments available to PCLinuxOS users, with the "clunkiness" removed.

Before we go too much further, here is the short script (below). You can enter it by hand, copy and paste it from the pages of the magazine (into your favorite plain text editor, such as Mousepad, Leafpad, Geany, Kwrite, Kate, etc.), or download it from the magazine website. If you choose the latter, don't forget to remove the ".txt" file extension, and to make the file executable (chmod +x, for example). KDE users will need to also install xdotool from Synaptic, and e17 users will need to enable the DBus Extensions module. The line numbers below are just to help keep you oriented, and can be (must be) omitted.


  function make_js {
       cat > $js <<_EOF
      var wallpaper = "$X";
      var activity = activities()[0];
      activity.currentConfigGroup = new Array("Wallpaper", "image");
      activity.writeConfig("wallpaper", wallpaper);
      activity.writeConfig("userswallpaper", wallpaper);

 function kde_wallpaper {
   qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole $js > /dev/null
   # sleep 2
   xdotool search --name "Desktop Shell Scripting Console -- Plasma Desktop Shell" windowactivate key ctrl+e key ctrl+w
   rm -f "$js"
   dbus-send --dest=org.kde.plasma-desktop /MainApplication org.kde.plasma-desktop.reparseConfiguration
   dbus-send --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ReloadConfig
   dbus-send --dest=org.kde.kwin /KWin org.kde.KWin.reloadConfig
   # kbuildsycoca4 2>/dev/null && kquitapp plasma-desktop 2>/dev/null ; kstart plasma-desktop > /dev/null 2>&1

 function xfce_wallpaper {
   xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$X"

 function lxde_wallpaper {
   pcmanfm -w "$X"

 function mate_wallpaper {
   gsettings set org.mate.background picture-filename "$X"

 function e17_wallpaper {

   echo 'images { image: "'$FileName'" LOSSY 90; }' > $edcFile
   echo 'collections {' >> $edcFile
   echo 'group { name: "e/desktop/background";' >> $edcFile
   echo 'data { item: "style" "4"; }' >> $edcFile
   echo 'data.item: "noanimation" "1";' >> $edcFile
   echo 'max: 990 742;' >> $edcFile
   echo 'parts {' >> $edcFile
   echo 'part { name: "bg"; mouse_events: 0;' >> $edcFile
   echo 'description { state: "default" 0.0;' >> $edcFile
   echo 'aspect: 1.334231806 1.334231806; aspect_preference: NONE;' >> $edcFile
   echo 'image { normal: "'$FileName'";  scale_hint: STATIC; }' >> $edcFile
   echo '} } } } }' >> $edcFile
   edje_cc -nothreads ~/tmp/SlideShow.edc -o $OUTPUT_DIR/SlideShow.edj
   sleep 2 && rm -f ~/tmp/SlideShow.edc
   echo 'Enlightenment e17 SlideShow.edj file created'
   enlightenment_remote -desktop-bg-del 0 0 -1 -1
   enlightenment_remote -desktop-bg-add 0 0 -1 -1 $OUTPUT_DIR/SlideShow.edj;

 function usage {
   printf "%s\n%s\n\n%s\n%s\n\n%s\n\n%s" \
   "Automatically set a random image as the desktop wallpaper,"\
   "from the user's ~/Wallpaper directory."\
   "Idea from a script by Just17. Written by Paul Arnote for PCLinuxOS."\
   "Originally published in The PCLinuxOS Magazine (, Jan. 2014 issue."\
   "Works for KDE4, Xfce, LXDE, Mate and e17 desktops."\
   "Usage: $0 [arguments]"\

   printf "\n %s\t%s" \
   "-h, --help" "This help text"
   printf "\n %s\t\tSetup for the %s" \
   "--xfce"    "XFCE4 Desktop"\
   "--mate"    "Mate Desktop"\
   "--lxde"    "LXDE Desktop"\
   "--kde4"    "KDE4 Desktop"\
   "--e17"    "Enlightenment Desktop"
   printf "\n"


 if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "" ]; then

while true; do
X=`find $DIR -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n1 -z`

   # For Xfce
   if [ "$1" == "--xfce" ]; then
   # For LXDE
   if [ "$1" == "--lxde" ]; then
   # For Mate
   if [ "$1" == "--mate" ]; then
   # For KDE4
   if [ "$1" == "--kde4" ]; then
   # For e17
   if [ "$1" == "--e17" ]; then
# If using Cairo-Dock add the following line
#         killall cairo-dock && sleep 0.3 && exec cairo-dock

   sleep 10m

exit 0

How It Works

Like I mentioned earlier, I've "reused" some of the script code from the NatGeo and Bing wallpaper scripts, which appeared in the September 2013 and October 2013 issues of The PCLinuxOS Magazine, respectively. These "code blocks" specifically set the wallpaper for each of the desktop environments. Why reinvent the wheel? Let's just use that which we already know that works.

As it is setup, the script looks for your wallpaper files in your /home/username/Wallpaper directory. For me, and a lot of other users, it's advantageous to keep all wallpaper image files in their own directory, separated from other image files. I recommend this approach to keeping your files organized. If you don't have a /home/username/Wallpaper directory, create one and fill it with your wallpaper image files. If you have your wallpaper image files organized differently, feel free to change line 83 to reflect your desired directory.

Line 90 sets up a loop. In line 91, a random *.jpg or *.png file is read by the find command, and is stored in the "X" variable. This variable is then used by the various desktop subroutine functions to set the desktop wallpaper.

Still within the loop, line 117 of the script sets up the delay before the next random wallpaper image is displayed. The script is set up to change the wallpaper every 10 minutes (hence, the sleep 10m command). If you want your wallpaper to change every 30 minutes, for example, change the sleep 10m command to sleep 30m.

If you want some offbeat time, such as changing your wallpaper every 10 minutes and 23 seconds, you will have to change the command to sleep 623s (10 minutes x 60 seconds = 600 seconds + 23 seconds = 623). The "s" parameter tells the sleep command to use seconds, rather than minutes. Seconds is the default time interval for the sleep command, so sleep 623 works just as well as sleep 623s.

Alternatively, you could also use 10.383m, since sleep is one of those rare commands that will recognize and use a floating point number, rather than just using whole integers as most other commands want. During testing, I had the sleep command set to sleep 10s, so my desktop wallpaper changed every 10 seconds. Finally, the loop is closed in line 119.


Because of the reuse of the code from the previously mentioned scripts, the same caveats for those scripts also apply to this script. Instead of rehashing them here, I'll refer you to the articles that discuss those previous scripts.

If you have Xfce set up to manage the wallpaper slideshow with its own built-in utility, using this script will cause the Xfce desktop wallpaper manager to revert back to single image mode.


First, be sure you've saved the script to a directory that exists in your path statement. I have a "special" directory within my /home directory, called "Scripts" (without the quotes), that I've inserted into my system's path statement. I put all of my custom scripts there, and it makes it simple to call them from a terminal session, from a Thunar custom action, or any other place where you enter a command. Alternatively, you will have to enter the full path and full filename of the script, if you place it in a directory that is not in your path statement.

As with the other scripts in its "lineage," you launch the script with the command line switch that matches the desktop environment you are running. Hence, --kde4 will launch the script and tell it to use the KDE subroutines/functions to control the changing of the wallpaper. The other command line switches are --xfce, --lxde, --mate and --e17. Issuing the command, without any parameters -- or with either the --help or -h command line switch -- will display the command line switches, and then exit.

With this script, it makes it easy to issue a command in your favorite desktop environment's startup utility to automatically start the script every time you log into your desktop.


Now, the users of all desktop environments can enjoy a wallpaper slideshow, without having to resort to utilities that work only on one or two desktop environments, or having to deal with clunky interfaces or commands. Now, users can gather around ONE tool that handles a desktop wallpaper slideshow, regardless of the environment. Users who have installed multiple desktop environments should find this particularly beneficial.

Previous Page              Top              Next Page