(Xubuntu) How to set the wallpaper using the command line?
Solution 1:
In Xfce land, that's
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set /usr/share/backgrounds/xfce/xfce-blue.jpg
(Substitute the file path you want, of course.)
xfconf-query --channel xfce4-desktop --list
lists all related properties, in case screen0/monitor0 isn't the one.
Solution 2:
For xfce4 in Xubuntu 14.04, use property /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image instead of /backdrop/screen0/monitor0/image-path
You also need to set DBUS_SESSION_BUS_ADDRESS environment variable like this:
PID=$(pgrep xfce4-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
In my case I wanted to rotate the wallpaper (random image from a selected folder) once a day, but I turn-on my PC irregularly, so I solved it by running a script from cron every half-hour, but only take effect once a day.
entry in crontab (add it via crontab -e
command):
0,30 * * * * /home/lucifer/scripts/rotate-wallpaper.sh
rotate-wallpaper.sh:
#!/bin/bash
wallpaperdir="/home/lucifer/Pictures/wallpapers"
datefile="/home/lucifer/.wallsw"
thisday=$( date +%j )
wallfiles=($wallpaperdir/*)
randompic=`printf "%s\n" "${wallfiles[RANDOM % ${#wallfiles[@]}]}"`
PID=$(pgrep xfce4-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
if [ -f "$datefile" ]
then
lastday=$( cat "$datefile" )
if [ "$lastday" != "$thisday" ]
then
date +%j > "$datefile"
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image --set $randompic
fi
else
date +%j > "$datefile"
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image --set $randompic
fi
Note: -If you are using non-English system locale, the property can have a different name. The best way to find out the property name, open a terminal window, and run this command:
xfconf-query -c xfce4-desktop -m
This will turn on monitoring of xfce4-desktop properties. Now change your background manually. You should see the property name which was affected by this change in the terminal window. Use this property name if it's different from /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image
Solution 3:
Setting image-path
has no effect at my system (XFCE 4.12, Debian buster/sid).
I use the following for setting the background image of all workspaces:
xfconf-query --channel xfce4-desktop --list | grep last-image | while read path; do
xfconf-query --channel xfce4-desktop --property $path --set <path>
done