0

When running

/usr/bin/xfconf-query -v -c xfce4-desktop \
  -p /backdrop/screen0/monitorHDMI-1/workspace0/last-image \
  -s $HOME/Photos/somephoto.jpg

on the command line, it sets the background image as expected.

When I let this run by cron, it does not work. The difference is likely in the environment variables, because if I prefix the above on the command line with env -i it does not work either.

What is a bit annoying is that there is no error output and even the exit code seems to be 0 as if all is OK. I checked /var/syslog but there was no output either. (No output on the command line, and I know how to capture cron output, this is not the problem.)

I will experiment with the output of env and all those XDG_* variables are surely good candidates, but if somebody could tell which ones are actually relevant and ideally where this is documented that would be great.

EDIT: DISPLAY=0.0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus as part of the env -i does the trick where 1001 is my user id.

Which prompts the more general and probably better question: what is the correct way to run a cron job depending on the graphical UI on behalf of a user such that it

  • just does not run if the user has no graphical UI running (xfce, gnome, ...)
  • sets up the environment correctly to actually be able to run the job

If it is not cron, what then (apart from a looping script with sleep started with the GUI session)?

EDIT2: This https://unix.stackexchange.com/a/111190/140503 looks like a useful and easy enough workaround. If there is nothing more geared to the task meanwhile, we can close this as a duplicate.

Harald
  • 898

0 Answers0