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



Question:

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?


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

Try

gsettings set org.gnome.desktop.background picture-uri file:///your/picture/location.jpg  

The file:// is required.


Solution:4

Don't use cron. Instead use the startup script. Although you can use cron but I don't prefer it in this situation because it is user specific.

Do it this way:

sudo vi /etc/rc.local  

add the following at the end of file

sudo -u YOURUSERNAME -g $( id -g YOURUSERNAME ) xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set /usr/share/backgrounds/xfce/xfce-blue.jpg  

and make sure you replace YOURUSERNAME with your current user. And replace /usr/share/backgrounds/xfce/xfce-blue.jpg by the real path of the new background image and make sure your user has permission to read the image


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »