by Paul Arnote (parnote)
In this, the eighth article in the "Xfce Power User Tips, Tricks & Tweaks" series, we'll take a look at leveraging and tweaking Xfce's built-in desktop wallpaper slideshow capabilities. I actually have two incarnations of this tweak, each approaching the task from different directions.
To understand what we're about to do, we first need a basic understanding of Xfce's Desktop Settings applet. This applet is the "control center" for almost everything that pertains to your Xfce desktop -- at least, in a visual sense. It's where you set the wallpaper, whether to display a context menu when you right click on the desktop, the brightness of the desktop wallpaper, and what icons to display on the desktop (if any at all), among other settings. Most users' will be most interested in the "Background" tab, which is the first one displayed, and that's what we'll restrict our discussion to for this article.
You can open the Desktop Settings applet by two slightly different ways. The fastest way is to right click on a "blank" area of the Xfce desktop, and select "Desktop Settings" from the context menu. You can also access it from the Xfce Settings Manager.
By default, Xfce is setup to display a single image as the desktop wallpaper. Thumbnails of the images available for use as wallpaper images are shown in the list on the left upper side of the dialog box. On the right upper side of the dialog box, your choices are "Single Image" (the default), "Image List" (what we're going to end up using), and "None" (where Xfce displays no image and a single color or a gradient between two colors).
Below the thumbnail display list are three buttons, labeled "+", "X" and a square with a + in the lower left corner (hereinafter referred to as the "New List" button). While in the "Single Image" mode, only the + button is active. Clicking on this button will allow you to select another image -- like one of your own images -- besides the default images, which are stored in /usr/share/backgrounds/xfce and /usr/share/xfce4/backdrops/.
Next to those three buttons is a drop down list button, with "Style" next to it. By default, it is set to "Auto." However, you can also choose from Centered, Tiled, Stretched, Scaled and Zoom. Most of the time, the Auto setting will serve most users well, setting the wallpaper to fill the desktop dimensions.
At the bottom (grayed out in the image) is another control, called "Change the background (in minutes). This control is only available when the "Image List" option is selected. Simply set how long you want to wait before the wallpaper image is changed.
So, let's select "Image List" from the "Image" selection area in the upper right corner of the dialog box. After you do that, the X and New List button to the right of it are activated, as well. The control at the bottom of the dialog box is also now activated and ready for use.
You will notice that once we selected Image List, we don't have any wallpaper displayed. That is because we don't have a wallpaper list yet. Click on the New List button, and select a directory to place the list, and enter a filename for your new image list. You can name it anything (I called mine "Test"), and you don't have to supply a filename extension. Now, click on the + button, and add an image from your hard drive to the list. Keep repeating this procedure for every image you want to add to the image list.
After you add more than three images to the list, you won't see the thumbnail list being updated. Don't worry -- the images are being added to the list. If you want to refresh the list, close the Desktop Settings dialog, then reopen it. This process can become a bit arduous, especially if you have a lot of images that you want to put into your image list.
Add To Wallpaper List
If you have wallpaper images scattered around a bit, then this Thunar Custom Action is for you. With it, you can right click on an image file (*.png or *.jpg), or multiple image files, and add the image(s) to any image list you want/specify.
Enter "Add To Wallpaper List" into the "Name" field, and "Make a list of wallpaper images for an Xfce desktop slideshow" into the "Description" field. Now, enter the following into the "Command" field:
L="$(yad --title="Image List Filename" --entry --entry-label="Please enter the filename")"; if [ ! -e $L ]; then echo "# xfce backdrop list" >$L; fi && for file in %F; do echo $file >>$L; done
Under the "Appearance Conditions" tab, leave the file pattern set to the default value of *, and place a checkmark in front of "Image Files."
The command allows you to specify the name of the image list file you want to create or add to (remember, you don't need to supply a file extension). If the file doesn't already exist, it is created. The first line of the file, if it doesn't already exist, is written out to the new file. That line is "# xfce backdrop list" and is vital for the file to be recognized for what it is: an image list for the Xfce Desktop Settings. Otherwise, it skips writing that vital first line. Then, the files are appended to that file one at a time, with the redirection command (>>) that tells Linux to append the path and filename of the image to the specified image list file.
Now, whenever you right click on an image (or multiple images), you can select "Add To Wallpaper List" from Thunar's context menu. Be sure to hold down the Ctrl key on the keyboard to select multiple images. The image's (or images') path and filename will be added to the wallpaper list that you specified in the initial dialog box.
Create Wallpaper List From Directory
If you are a bit more organized with how you store your wallpaper files, this Thunar Custom Action is for you. I tend to keep all of my wallpaper images in a folder in my /home directory, called Wallpaper. Within that directory, I have subdirectories with categories of images. I have a subdirectory for images downloaded from National Geographic, others downloaded from Bing, space images, bicycling, architecture, and so on. With this custom action, I can create custom wallpaper image lists for each folder.
Enter "Create A Wallpaper List From Directory" in the "Name" field, and "Make a wallpaper list from a directory of JPG and PNG images" in the "Description" field. Now, enter the following into the "Command" field:
echo "# xfce backdrop list" > %n/%n; ls -1 %f/*.* |egrep *.'[jJ][pP][eE][gG]|[jJ][pP][gG]|[pP][nN][gG]' >>%n/%n
Under the "Appearance Conditions" tab, leave the file pattern set to the default value of *, and place a checkmark in front of Directories. Now, when you right click on a directory filled with JPG and PNG image files, they will all be added to a new image list file that is placed inside the directory directory that we initially selected.
The first echo command writes out the necessary first line (# xfce backdrop list) to the file, and then lists the contents of the directory (ls), one line at a time (-1), and appends each qualifying file (jpg/JPEG/png) to a the image list file.
If you use this custom action to create an image list file from a directory, and you add more files to the directory, you may want to delete any existing image list file before creating a new one. Nothing bad will happen if you don't. But because there is no checking to see if a filename is already listed, all of the previous files will be listed again, appended to the end of the file, along with the new files. Because the previous files will be listed twice and the new ones once, the previous files will be more likely to be displayed than the new ones, due to the random way that Xfce displays images on the image list file. Also, the file will be much larger than it needs to be, if you don't delete the old image list file.
Putting The Image List To Work
Here is an example of the image list file that is created:
# xfce backdrop list
As you can see, it's nothing more than a list of eligible graphic files, with their complete path and filename listed, one per line. The first line of a Xfce image list file must always be "# xfce backdrop list" or Xfce will not recognize it as such.
Back in the Desktop Settings window, click on the New List button and select the image list file that you just created. Remember, your new image list file is inside the directory that you chose. Or, you can select the image list file you created with the previous custom action.
You can select to rotate or change the background image by placing a checkmark in front of "Change the background (in minutes)" option, and set the number of minutes you want Xfce to change your wallpaper. Because I was testing, I had the time set to only one minute. More realistically, you'll probably want to set a longer time interval. The default value is 10 minutes.
The selection of which image to display is completely random, selected from the image list. If you choose to not rotate your wallpaper images on a timed basis (by leaving the "Change the background" setting unchecked), Xfce will display a random wallpaper image every time you log into your Xfce desktop, and display that image for the duration of your session.
One word of caution, though. If you use the NatGeo-POD or Bing scripts from the September and October issues of The PCLinuxOS Magazine, respectively, and have them "set" to change your wallpaper, the Desktop Settings will switch back to "Single Image" mode. If you simply download the images with those scripts -- without having them set the images as your wallpaper by using the -d command line switch -- it will not change the Desktop Settings back to "Single Image" mode. But keep in mind your newly downloaded images won't be in the image list file, until you either add that new image to the relevant image list file, or until you delete the old list and rebuild it (if you are keeping all of your NatGeo and Bing images in their own directories and use the custom action that builds the image list file from the directory).
As you can see from the articles in this series, there are a lot of "extras" you can use to customize Xfce to your liking. These tips, tricks and tweaks can add a lot of extra "horsepower" to your Xfce computing experience.
You are limited only by your imagination. I'm certain that there are Xfce tips, tricks and tweaks that I have missed or not discovered yet. Of course, the better your understanding of the command line, the more you can imagine being done. The ones I've presented to you are the ones that I have found a recurring need for. There are some that are not used frequently, but their presence definitely is appreciated for those times when I do find a need to use them. There are others that I use almost daily.
If you come up with -- or come across -- additional Xfce tips, tricks and tweaks, I'd love to hear about them. Feel free to send me a PM in the PCLinuxOS forum, or send me an email at email@example.com. I'll be happy to write them up for The PCLinuxOS Magazine.