0

I have tried several approaches to fixing this issue, but all I want to do is change the desktop wallpaper when this script is run in cron. Below is what I have so far.

PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
sudo gsettings set org.gnome.desktop.background picture-uri file:///home/mark/Pictures/Background_Pictures/CAP.jpg

I get the following error when I run this in cron.

(process:17154): dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY

I know that part of the problem is that I need to set the DBUS_SESSION_BUS_ADDRESS variable, but I have and it seems to have a valid value.

I'm at a loss as how to accomplish this. Does anyone have a valid solution for this?

1 Answers1

1

Found the solution. I used the following script.

PID=$(pgrep gnome-session) 
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) 
gsettings set org.gnome.desktop.background picture-uri "file:///home/mark/Pictures/Wallpapers/CAP.jpg"

However, the issue was in my cron file. I was using the line

***** root sh /home/mark/scripts/desktop.sh

when it should have been

***** mark sh /home/mark/scripts/desktop.sh

When I ran the script in cron with my own privileges, then I was able to run the script in cron successfully.