4

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?

uldics
  • 43

2 Answers2

8

You can use the dconf tool for this.

For example:

dconf write /org/mate/desktop/background/picture-filename "'PATH-TO-JPEG'"

Note the quoting for the image filename/path. dconf expects a string so needs the single quotes, and your shell will need the double quotes to keep the single quotes.

Tinker
  • 181
  • 1
  • 3
  • works fine. please note the quoting in PATH-TO-JPEG: you need single-quotes (dconf syntax, I suppose) enclosed in double quotes (for bash). – Alan Franzoni Oct 01 '18 at 11:49
  • This other question's answer seems to indicate that while indeed dconf will work, gsettings is a preferred front-end to dconf: https://askubuntu.com/a/249924/234023 – Justin Mar 11 '20 at 20:19
4

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}]}
Bernard
  • 56
  • Excellent! Thanks, this worked, both the Mate location and object in there were wrong for me before. This works now: gsettings set org.mate.background picture-filename "$(find ~/Pictures/Wallpapers -type f | shuf -n1)" – uldics Nov 04 '19 at 19:55
  • Hmm, on Ubuntu 19.10 this actually only works when put in a terminal, but not from Mate autostart or from Mate panel Custom Application Launcher - it just changes to blue background, as if file not found. Any suggestions? Do I have a problem with those weird parentheses, or some environment variable must be set? – uldics Nov 16 '19 at 18:38
  • For the record, for gsettings to work, we need DBUS_SESSION_BUS_ADDRESS, so this command has to be run before gsettings: export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep mate-session)/environ|cut -d= -f2- | tr -d '\0') – uldics Mar 21 '20 at 12:59