I have a script to set the desktop wallpaper image that essentially does the following:
The script works fine if I run it manually. However, if I run it as a cron job, it returns the error:
An error occurred while attempting to set the Plasma wallpaper:
Not connected to D-Bus server
How can one change the desktop wallpaper using a cron job?
It’s probably because the cron job does not have access to your Dbus session. I thought Plasma already comes with a slideshow function, why not use that?
It’s probably because the cron job does not have access to your Dbus session.
Is there any way to get that information and pass it to the script?
I thought Plasma already comes with a slideshow function, why not use that?
Right now that is what I am doing…
Ultimately, though, I would like to do this all using a script that I can transfer from one computer to another without having to do extra steps.
I believe that wallpaper setting are stored in ~/.config/plasma-org.kde.plasma.desktop-appletsrc.
Double checking, mine shows my different wallpaper settings across both my monitors and for all of my Activities.
You could try a systemd service and timer that runs under your user session. That would likely be able to change it.
Thanks @claydoh and @Justin
~/.config/plasma-org.kde.plasma.desktop-appletsrc did the trick!
A systemd service sounds like an overengineered solution for this and I am not savvy enough to come up with that anyway.
But eventually I decided to go with the simpler solution of just using the Slideshow mode. My script will fetch a wallpaper image every night and place it in a directory.
For reference, the systemd solution would look something like this. The systemd timer essentially replaces the cron job:
Description=Periodically update the desktop background
# Trigger when hour and minute are 0 (i.e. midnight)
OnCalendar=0 0 * * *
Description=Update the desktop background with the latest image from somewhere
# Your script that fetches the image and sets it
Once you’ve created these two files, you just need to run
systemctl --user enable update-desktop.timer
to enable it.
put the following at the beginning of your cron script:
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"