Switching desktop backgrounds in XFCE4
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.
Flattr
A cleaner solution would be
A cleaner solution would be to ln -sf $XAUTHORITY ~/.Xauthority in your session startup.
It could be.
I can never remember WTF runs on session startup these days and it was actually less work for me to write the above script, than to spend the time working out what runs on startup.
Really useful script, thanks
Really useful script, thanks for sharing.
A script called from ~/.config/autostart
I use the following non-perfect script called from an entry in ~/.config/autostart.
Entries in ~/.config/autostart are easy to set up in `xfce4-session-settings` ("Sessions and Startup")
The script takes an optional argument for how long it should sleep between `xfdesktop --reload`
It also checks that the user aren't already running the script.
#! /bin/bash if [ "m$DISPLAY" = "m" ] ; then echo "No DISPLAY!" ; exit 0 ; fi _LOCKFILE="/tmp/._xfdesktop_reload-${UID}.lock" if [ -f $_LOCKFILE ] ; then echo "$0 already running." ; exit 0 ; else touch $_LOCKFILE fi while true ; do case "m$1" in "m--sleep" | "m-s" | "m-sleep" ) sleep ${2:-20m} ;; "m--help" | "m-h" ) echo "${0} -h, --help Print this help" ; echo " -s TIME, --sleep TIME Sleeps TIME between reloads." exit 0 ;; *) sleep 20m ;; esac xfdesktop --reload ; doneSo what prompted the switch to XFCE, and was it worth it?
I've been considering it. I had the ghastly experience of Gnome3 on a sid install, and have decided to get of that gnome boat to no where.
I've looked at XFCE, but am a bit addicted to Compiz, and not sure I can make that combo work the way I want. I have toyed with cairo-dock tho, and I like that. I'm thinking cairo-dock with compiz as the window manager might be worth a look.
:D
Was XFCE worth switching to?
I'd say definitely. It's given me back an interface I'm used to, so I can be productive again.
I expect I'll switch to Gnome 3 in 3-6 months, when I have some time to fiddle, and when someone has written some plugin to let me turn off the 3d animation stuff - plugins already seem to exist for all my other annoyances.
Overall as I looked around increasingly, the Gnome3 environment seems increasingly positive in it's customisability, and I'm sure those options will make it into the distributions in due course.
Cheers,
Andrew.