Slick Wallpaper Rotation in Ubuntu
After I got Ubuntu 9.10 Beta running, I thought to throw some of my personal touches in there, like updating the background wallpaper. While browsing I notice a layered looking selection of space photos that at first glance I thought was my Pictures directory, where I have a number of simiar photos. It was not, but it did provide a preview to a fun new wallpaper toy.
Looking a little more closely, and after a quick Google search, I found that I wasn't alone in my confusion or excitement. It seems that for a while now there's been a poorly-documented feature that allows an XML file instead of an image to be the background. The XML file, of course, is formatted with a few specifics (undocumented so far as I can tell) that name files to display and ways to transition between them. Here's a sample and a quick discussion of what I think I've worked out of it.
<background>
<starttime>
<year>2009</year>
<month>10</month>
<day>27</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>
<static>
<duration>900.0</duration>
<file>/home/jkwarren/Pictures/120_01_full.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/home/jkwarren/Pictures/120_01_full.jpg</from>
<to>/home/jkwarren/Pictures/132_01_full.jpg</to>
</transition>
<static>
<duration>900.0</duration>
<file>/home/jkwarren/Pictures/132_01_full.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/home/jkwarren/Pictures/132_01_full.jpg</from>
<to>/home/jkwarren/Pictures/120_01_full.jpg</to>
</transition>
</background>
(Note you don't need the marked out bits in the <transition/> blocks...a little more detail follows...)
So here I've provided a sample with a pair of files that will alternate every five 900 seconds (15 minutes for the time challenged). I poached a few images from NASA's APOD project. They're located in my home folder's Pictures directory. I just put the full file path and name in the <file/> and other elements that need the files.
The <starttime/> element seems to provide some time-based boundary, in this case midnight yesterday (as I type this), for which it will determine the timeslice for the static or transition to use. In one of the examples I found, the <duration/> in the static blocks were just short of six hours, giving a kind of morning, midday, evening, and overnight image.
The <static/> block displays an image that doesn't move. Its <duration/> element gives a time, apparently in seconds, to display the image. The <file/> element is the file. From what I can gather on the forums I searched when looking for definitions, this needs to be an absolute path. If the image named is not found, the block is still used, but the solid color background is shown instead, so check yer spellin'.
The <transition/> block seems to provide a nice, well, transition betwen the two, blending over the course of five seconds as indicated by its <duration/> element. It'd be interesting to see what other types than "overlay" attribute noted in the sample; I can imagine fades and wipes and other random selections. Through experimentation I've found that the <transition /> block is not required. This makes the file much easier to maintain as it just contains the <starttime/> and <static/>blocks!
The XML file seems to be read in order, so the first transition is from the file in the first static block to the file in the second, likewise the second transition is from the second static file back to the first. I've actually got dozens of files, each transitioning between the next, with the last transition returning to the first file again.
Finally, to add this file as an option for the desktop background was pretty simple, too. I simply saved the XML file with my pictures, for easy finding and alteration later, named apod-background.xml, to give homage to the images' source. I then right-clicked my desktop and chose "Change Desktop Background" from the context menu. The "Appearance Preferences" dialog opened, right to the Background tab. I bonked the "add" button, changed the selection filter from "images" to "all files," browsed to my Pictures folder and selected the XML file. When I bonked the "open" button, a new stack appeared in the selection of images. Bonking the arrow buttons skipped through the images. Having it highlighted when I closed the dialog box changed my background to one of the images in the list!
After watching for a few minutes I did go back and change the style to "zoom" to make sure that all of the images filled the screen (some weren't), but that's it. I edited the file to add more images, and each time I saved the XML file it flipped my background to a new image.
Now every 15 minutes, I get a new view of space as my background.
2 comments
Comment from: Ben Visitor
Hm, doesn’t seem to work for me. Only one random picture seems to be shown forever.
The picture only changes when I am saving the xml file again. Everytime I save the xml-file the desktop changes! Weird :)
Perhaps this background changing doesn’t work properly with dosktop effects turned on?
Awesome… now… if only linux n00bz like me could make sense of this.
A, 1.) open this, 2.) copy and past this, 3.)save here, 4.) viola!
… walk through would be awesome.