In a RHEL73 system with XFCE I wanted to change the wallpaper from a script run by root, so I searched and found that, in theory, it could be done using
xfconf-query -c xfce4-desktop \ -p /backdrop/screen0/monitorDP-5/workspace0/last-image \ --set PATH_FILE
If I launched that command from a terminal from within xfce with a normal user it worked, but it didn’t work if I launched it with
root, nor launching it from a tty or the provisioning script. The error I was getting was:
Failed to init libxfconf: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
I started diggin up and it seemed related to Dbus, as any configuration changes made with
xfconf-query were actually relayed through Dbus. I tried running the same command prepending
dbus-launch, and now the error was different:
Property “/backdrop/screen0/monitorDP-7/workspace0/last-image” does not exist on channel “xfce4-desktop”
I kept reading about DBus, discovered
dbus-send and managed to replicate the call
xfconf-query was doing, like this:
dbus-send --session --print-reply --type=method_call --dest=org.xfce.Xfconf /org/xfce/Xfconf org.xfce.Xfconf.SetProperty string:'xfce4-desktop' string:'/backdrop/screen0/monitorDP-7/workspace0/last-image' variant:string:'IMAGE_PATH'
Same as before, it worked from the xfce4 terminal, but not from anywhere else. Kept reading about DBus, remembered that each session for each user has a different DBus session bus, so any changes I did from a root or a tty session would not be reflected upon the main XFCE4 session.
I tried fetching the
DBUS_SESSION_BUS_ADDRESS of the main xfce4-session in order to match the session bus, but it didn’t work. I was doing it like this:
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pidof -s xfce4-session)/environ |cut -d"=" -f2-)
xfconf-query command failed as in the first case (with:
"Failed to init libxfconf..."). However, it seemed that in order to have access to the session bus you need to match both the address and the user, so combining the two I finally managed to do it:
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pidof -s xfce4-session)/environ |cut -d"=" -f2-) su YOUR_USER -m -c 'xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDP-5/workspace0/last-image --set IMAGE_PATH