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?

9
  • Are you trying to use cron to set your desktop wallpaper? Jan 25, 2017 at 5:32
  • Yes. I can't get cron to successfully run the command I specified above without errors. Jan 25, 2017 at 5:36
  • Within System Settings -> Appearance it can cycle through wallpaper I believe. Jan 25, 2017 at 5:40
  • I'm trying to set specific times on a particular day when I want the wallpaper to change. Not just like a slideshow. Jan 25, 2017 at 5:43
  • a) do you need sudo? and b) you might need dbus-launch
    – muru
    Jan 25, 2017 at 5:44

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .