(Xubuntu) How to set the wallpaper using the command line?

19,954

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

Solution 4

The following code can be used to set the image for the xfce desktop Just change the address of the image, the code is on the fourth line and run it in a bash file

xres=($(echo $(xfconf-query --channel xfce4-desktop --list | grep last-image)))

for x in "${xres[@]}"

do
    xfconf-query --channel xfce4-desktop --property $x --set "/home/mf/Desktop/a.png"
done
Share:
19,954

Related videos on Youtube

John
Author by

John

Updated on September 18, 2022

Comments

  • John
    John over 1 year

    I've done a lot of googling but haven't been able to find a solution to my problem.

    I am a teacher and I'm using Xubuntu on some student computers. I have everything locked down pretty good, but I can't figure out how to restrict users from changing the wallpaper without having to out the whole machine in Kiosk mode. I don't care if they change it during their work session, but I would like to create a crontab that resets back to the original .png at reboot.

    I'm hoping for a simple cron entry but I'm willing to ease into the world of shell scripts if that's what it takes.

    Any ideas?

  • John
    John over 10 years
    I tried it without any luck. Since I'm running XFCE, do I even have gsettings? The syntax of the command makes sense to me, but I don't know how to make it apply to Xubuntu.
  • John
    John over 10 years
    When I run that in the command line, it works like a charm. When I try to add it to cron though, it doesn't do anything. Any ideas? `
  • John
    John over 10 years
    Created the shell script and made it executable. It runs when double clicked and I can run it in the command line. I tried adding it to cron with @reboot as the time but it doesn't seem to be working. Do I need to add something to cron other than just the path to the script?
  • kamil
    kamil about 10 years
    @John It doesn't work in cron because cron work under root privilege and this is a user specific background. try changing the command to run as your user
  • Bugster
    Bugster about 9 years
    You need to set the DESKTOP environment variable if you want to use it in a cron job. If you only have one X server running you could just do: DESKTOP=:0 xfconf-query ... in your cron job.
  • Ilmari Karonen
    Ilmari Karonen almost 9 years
    For me, --property /backdrop/screen0/monitorLVDS1/workspace0/last-image did the trick.
  • Sam Watkins
    Sam Watkins almost 9 years
    you could run a script that does this as an xfce startup app
  • Stéphane Gourichon
    Stéphane Gourichon over 7 years
    Why was this downvoted? The OP requested a way that effects at reboot. Perhaps the OP needed to apply it to several users, but hasn't explicitly stated so. This answer seems okay (haven't tested it, though). So, why the downvote?
  • Maxwel Leite
    Maxwel Leite almost 4 years
    For one-line and shorted params: xfconf-query -c xfce4-desktop -l | grep last-image | while read path; do xfconf-query -c xfce4-desktop -p $path -s /usr/share/backgrounds/xfce/xfce-blue.jpg; done
  • Stephen Michael Kellat
    Stephen Michael Kellat almost 3 years
    Explanatory text would make this a far better answer. A code block with no explanation does not fit site guidelines well.
  • محمد باقر فکوری
    محمد باقر فکوری almost 3 years
    @StephenMichaelKellat Thanks for the feedback. I apologize and I edited the answer