One of the things I liked about Gnome 2 was the ability to run a background 'slideshow' defined in an XML file with a list of background files to give me a change of scenery from time to time.

Switching to XFCE4 I can't seem to find a simple way to do that, but the ingredients are all there:

  • I can set the background image to a list
  • There's a handy-dandy xfdesktop command-line utility I can call to switch desktops

What's missing from the Desktop Settings is a setting for "switching background ever N minutes", which is kind of odd to not have, given the list thing being there - without my script it's only going to change every couple of weeks when I log in, or something. Not nearly often enough for me!

There's lots of stuff on the internet saying "Just run xfdesktop --reload in a cron job", but this does not work for me, since cron is running with a different environment, and so xfdesktop doesn't know where the X server is and doesn't have the necessary XAUTHORITY and DISPLAY settings.

If it was just DISPLAY that was needed it would be easy enough to set that in the crontab and be done with it - after all it doesn't change very often. XAUTHORITY is harder, since on Debian systems (and presumably others too) it has a random component in the name of a directory which lives in a directory without read permissions.

I solved it with this script, which steals those values from the environmnt of xfce4-panel, which will be running already:

#!/bin/sh
#

PANELPID="`/usr/bin/pgrep -U ${LOGNAME} xfce4-panel`"

stealEnvironment() {
  tr '\000' '\012' < /proc/$PANELPID/environ | grep -a "^$1=" | cut -f2- -d=
}

export DISPLAY="`stealEnvironment DISPLAY`"
export XAUTHORITY="`stealEnvironment XAUTHORITY`"

/usr/bin/xfdesktop --reload

So now I have my background image switching among my favourite photos again, and my Desktop is effectively back as it was a week ago.