Setting wallpaper from cron
Setting wallpaper from cron requires setting
cron runs with a very limited set of environment variables, you will need set a special variable, called:
Not the (what you would expect)
See also here how to do that.
Alternatively, you can use the simple script below. On startup, the script sets the corresponding wallpaper, then all the script does is wait until midnight, to change the wallpaper. Then again sleep until the next midnight and so on.
picsdir = "/home/jacob/Bureaublad/pics"
images = sorted([os.path.join(picsdir, pic) for pic in os.listdir(picsdir)])
secdata = time.strftime("%H %M %S").split()
seconds = (int(secdata)*3600)+(int(secdata)*60)+(int(secdata))
# calculate the sleep time until next midnight
day = int(time.strftime("%w"))
# the corresponding image from the set folder
image = images[day-1]
# set the image from gsettings
command = ["gsettings", "set", "org.gnome.desktop.background",
# calculate the time to sleep until next midnight
wait = calc_sleep()
How to use
- Create a directory with seven wallpapers
- Copy the script into an empty file, save it as
- In the head of the script, set the path to the wallpapers
Test-run the script:
The wallpaper, corresponding to the day of the week should be set.
If all works fine, add it to Startup Applications: Dash > Startup Applications > Add. Add the command:
/bin/bash -c "sleep 10 && python3 /path/to/wallswitch.py"