I've made a simple python script to change my wallpaper (Ubuntu 18.04) by randomly taking an image in a specific folder. I use gsettings command. It works when I run it manually, but I want to automate it with crontab.
I had the following error because crontab hasn't all variables I had when I run my script manually:
(process:xxxxx): dconf-WARNING **: 15:07:01.547: failed to commit changes to dconf: Impossible de lancer automatiquement D-Bus sans $DISPLAY X11
So I found some solutions like :
dbus_session_bus_address = 'PID=$(pgrep gnome-session | head -n1) && export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) && ' command = dbus_session_bus_address + 'gsettings set org.gnome.desktop.background picture-uri ' + getRandomImage()
It seems work for most people but I have a problem, my crontab hasn't permissions :
grep: /proc/$pid/environ: Permission denied dconf-WARNING **: 15:19:01.514: failed to commit changes to dconf: The address indicated is empty
So I run the script with
sudo crontab -e, but I have the following error :
dconf-WARNING **: 15:22:01.807: failed to commit changes to dconf: Connection is closed
Also, I prefer use my user crontab.. What is the best way to do that ?