Ubuntu – How to change desktop background on Mate with a command

command lineubuntu-matewallpaper

I have just installed Mate DE on Ubuntu 16.10. I want to change my desktop background automatically after each login. On LXDE this was done easily with immediate effect (sleep just for autoload after desktop is loaded) with the next command:

bash -c 'sleep 5; pcmanfm -w "$(find ~/Pictures/Wallpapers -type f | shuf -n1)"'

This is, of course, not working on Mate. I get this error:

Desktop manager is not active.

The only solutions I get for Mate involve mateconftool-2, which I do not have installed and it looks like it is deprecated. It should be replaced by something else, probably gconftool-2 or gsettings.

Just replacing the following mateconftool-2 command by gconftool-2 (this is from a few forums' posts I've read) does nothing:

mateconftool-2 -t string -s /desktop/mate/background/picture_filename $(find ~/Pictures/Wallpapers -type f | shuf -n1)

The gsettings command is accepted, but doesn't change the actual picture:

gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)"

Although I can see it has changed the value:

myusername@mypcname:~$ gsettings get org.gnome.desktop.background picture-uri 'file:///home/myusername/Pictures/Wallpapers/Horex-VR6-Cafe-Racer-33-LTD-2014-1920x1080-001.jpg'

How do I get it working?

Best Answer

You can do something like that

#!/bin/bash

# images directory
rep="/home/bernard/Images/FdsEcran"

# Create image list from directory
liste=("${rep}/"*)

# Compute the number of images
nbre=${#liste[@]}

# Random select
selection=$((${RANDOM} % ${nbre}))

# Image loading
gsettings set org.mate.background picture-filename ${liste[${selection}]}