How can I get one wallpaper for each day of the week?
So, I have an idea. To make me better aware of the day of the week, I want a custom wallpaper for each day. But I don't know how to accomplish that.
Does it exist any software that could do that for me? If not, could anyone help with setting up a script that can change the background for each day?
Make a script as this example called dailywallpaper.sh
:
#!/bin/bash
# Variables explained:
# [wallpaperpath]....The directory with your wallpapers.
# [background].......The wallpaper. For the current "Week" day make a symbolic
# link to the desired image. Name the line the a number
# between 1-7 with a dash and the name without extension.
# (ie. ln -s image.png 3-daily for the thrird day of the
# week)
# [default]..........The default wallpaper to set if the file matching the
# current day isn't found.
DBUS=$(ps aux | egrep "/gnome-session/.*\s--session=" | awk '{print $2}')
export $(strings /proc/$DBUS/environ | egrep DBUS_SESSION_BUS_ADDRESS)
day=$(date +"%u")
wallpaperpath="/home/userid/backgrounds/"
background="$day-daily"
default="manhattan-wallpaper-2.jpg"
# Default when the specified file isn't found.
newwallpaper="$wallpaperpath$default"
[[ -f "$wallpaperpath$background" ]] && newwallpaper="$wallpaperpath$background"
gsettings set org.gnome.desktop.background picture-uri "file://${newwallpaper}"
The script usage is explained in the script's comments. You can set the script to run via crontab
.
Crontab example entry:
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
0 0 * * * /home/myaccount/bin/dailywallpaper.sh
The Startup Applications app is needed if you are not logged in at midnight. The startup app will make the change when you log in. You can find the Startup applications app in the Ubuntu Dash: (Ubuntu Dash -> Startup Applications
).
The crontab
entry sets the background variable if you are logged in. The Startup Applications
app sets the variable if you were not logged in at midnight when the cron ran.
Using the two, the correct day's wallpaper will always show.
I would use cycling wallpaper:
Then I would use conky to display the day of the week:
From this web site: https://ubuntuforums.org/showthread.php?t=281865&page=2325&p=13554728#post13554728
And this picture: https://ubuntuforums.org/attachment.php?attachmentid=264010
It's very easy to have Conky to dislay MONDAY
in big capital letters. Check out the website and find an eye pleasing script and change it to suit your needs.
Setting wallpaper from cron
Setting wallpaper from cron requires setting gsettings
. Since cron
runs with a very limited set of environment variables, you will need set a special variable, called:
DBUS_SESSION_BUS_ADDRESS
Not the (what you would expect) DISPLAY
-variable.
See also here how to do that.
Alternatively
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.
The script
import time
import os
import subprocess
picsdir = "/home/jacob/Bureaublad/pics"
images = sorted([os.path.join(picsdir, pic) for pic in os.listdir(picsdir)])
def calc_sleep():
secdata = time.strftime("%H %M %S").split()
seconds = (int(secdata[0])*3600)+(int(secdata[1])*60)+(int(secdata[2]))
# calculate the sleep time until next midnight
return 86400+1-seconds
while True:
# weekday
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",
"picture-uri", "file://"+image]
subprocess.check_call(command)
# calculate the time to sleep until next midnight
wait = calc_sleep()
time.sleep(wait)
How to use
- Create a directory with seven wallpapers
- Copy the script into an empty file, save it as
wallswitch.py
- In the head of the script, set the path to the wallpapers
-
Test-run the script:
python3 /path/to/wallswitch.py
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"