5

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?

  • Possible to do. I can write a custom script that does the job. What are your requirements ? Have folder with 7 images numbered 1 through 7 ? Or maybe read everything from a configuration file ? Please explain more – Sergiy Kolodyazhnyy Oct 11 '16 at 22:48

3 Answers3

4

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 Startup Applications app

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.

L. D. James
  • 25,036
  • Crontab doesn't deal with GUI unless you add $DISPLAY variable to the command. Not the best way to do it – Sergiy Kolodyazhnyy Oct 11 '16 at 23:54
  • Thanks. I was in the process of testing the script. Thanks for the quick validation! Still debugging procedure. The example was something to get the OP started. – L. D. James Oct 12 '16 at 00:00
  • Good. Let me know if you want me to do additional tuning,testing and/or checks. I'm still waiting for OP's requirements , so will also be writing an answer, but I can help with yours too once I get back home – Sergiy Kolodyazhnyy Oct 12 '16 at 00:12
  • Hi @Serg setting the wallpaper (editing gsettings) does not require $DISPLAY, what you would expect, but the DBUS_SESSION_BUS_ADDRESS -variable. – Jacob Vlijm Oct 12 '16 at 07:42
  • Yes, that's what it does require . . .My mistake. Typically if it's a GUI app, you do need $DISPLAY variable, but gsettings isn't really a GUI app. Confused myself there – Sergiy Kolodyazhnyy Oct 12 '16 at 07:45
  • Thanks, this helps, although there seems to have been a mistake. The variable for day was for some reason declared after it was used. This resulted in the attempted use of -daily.png as the file when 3-daily.png was expected.

    I corrected the error, and it now works. Thanks.

    – Lars Erik Grambo Oct 12 '16 at 08:45
  • @LarsErikGrambo You're welcome. Thanks for testing and giving feedback. I guess I guess the variable got sorted wrong during the code cleanup for publishing. I had sourced the user input variable togeher. I'll fix it. – L. D. James Oct 12 '16 at 09:01
  • @LarsErikGrambo While updating the script, I made Sunday to be day 1 instead of day 0. – L. D. James Oct 12 '16 at 10:02
  • So the week starts on Sunday? Is this global, or based on local settings? Where I live, the week starts on Monday. – Lars Erik Grambo Oct 13 '16 at 09:02
  • @LarsErikGrambo By default applications that present arrays start with the first element as 0. So the 7 day week was 0-6. That meant the file (of your original comment 3-daily.png) was the 4th day of the week. I edited the code so that the first element would be 1 instead of 0. That will gives a 1-7 instead of 0-6. I notified you of the change in case you downloaded the update and your images lost sync. The first name day doesn’t matter. Just apply 1-7 to the days. – L. D. James Oct 13 '16 at 10:19
1

I would use cycling wallpaper:

enter image description here

Then I would use conky to display the day of the week:

enter image description here

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.

1

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

  1. Create a directory with seven wallpapers
  2. Copy the script into an empty file, save it as wallswitch.py
  3. In the head of the script, set the path to the wallpapers
  4. Test-run the script:

    python3 /path/to/wallswitch.py
    

    The wallpaper, corresponding to the day of the week should be set.

  5. 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"
    
Jacob Vlijm
  • 83,767