The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,054     Votes:  3     ✅ Solution
Tags: scripts   wallpaper  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

Title: Change dynamic wallpaper directory every season
ID: /2018/12/15/Change-dynamic-wallpaper-directory-every-season
Created: December 15, 2018    Edited:  January 6, 2022
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  true    Copy to clipboard:  false



The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron with entries.

I’ve approached this answer using the OP’s question “How do I develop a script?”. So I’ve deviated from usual method of simply posting a bash script and enhanced the answer with:

Top ToS Skip

When do seasons start?

From the Farmer’s Almanac:

Seasons of 2018

Season Astronomical Start Meteorological Start
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1

Top ToS Skip

Convert season start date to Day of Year

For our bash script to work we need to know what day of the year each seasons start.

$ echo $(date --date="March 20" '+%j')
$ echo $(date --date="June 21" '+%j')
$ echo $(date --date="Sep 22" '+%j')
$ echo $(date --date="Dec 21" '+%j')
# Reference:
## ```

# Create bash script: ``

Open the terminal using: <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>T</kbd>

Create the directory if it doesn't exist: `mkdir -p ~/bin`

Edit the script using: `gedit ~/bin/`

- **Note:** Lubuntu user's need to use `leafpad` instead of `gedit`

Copy and paste the following lines into `gedit`:

``` bash

<a id="hdr4"></a>
<div class="hdr-bar">  <a href="#">Top</a>  <a href="#hdr3">ToS</a>  <a href="#hdr5">Skip</a></div>

# !/bin/bash
# PATH: ~/bin
# DATE: December 15, 2018

# NOTE: Written for:

# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
   SpringDir="~/Pictures/Spring Slide Show"
   SummerDir="~/Pictures/Summer Slide Show"
     FallDir="~/Pictures/Fall Slide Show"
   WinterDir="~/Pictures/Winter Slide Show"

CheckTripWire () {
    # Our last season is in "~/Season Slide Show/CurrentSeason"
    LastSeason=$(cat "$LastSeasonFilename")
    [[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
    # We now know our season has changed.
    rm -f "$SlideShowDir"/{*,.*}           # Erase all files in target
    # Reference:
    echo "$Season" > "$LastSeasonFilename" # Record new season in target
    # Copy new slide show based on season
    if (( "$Season" == SPRING)) ; then
        cp -R "$SpringDir"/. "$SlideShowDir"/
        # Reference:
    elif (( "$Season" == SUMMER)) ; then
        cp -R "$SummerDir"/. "$SlideShowDir"/
    elif (( "$Season" == FALL)) ; then
        cp -R "$FallDir"/. "$SlideShowDir"/
        cp -R "$WinterDir"/. "$SlideShowDir"/

} # End of CheckTripWire () function.

<a id="hdr5"></a>
<div class="hdr-bar">  <a href="#">Top</a>  <a href="#hdr4">ToS</a>  <a href="#hdr6">Skip</a></div>

# Start of Mainline

DOY=$(date '+%j')                     # DOY = Current Day of Year
# Reference:

if ((DOY>=079 && DOY<172)) ; then
    Season="SPRING"                   # Spring has sprung!
    # Reference:
elif ((DOY>=172 && DOY<265)) ; then
    Season="SUMMER"                   # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
    Season="FALL"                     # Rake those leaves!
    Season="WINTER"                   # Shovel the snow!

<a id="hdr6"></a>
<div class="hdr-bar">  <a href="#">Top</a>  <a href="#hdr5">ToS</a>  <a href="#hdr7">Skip</a></div>

# Current season establish, now see if we tripped the wire

exit 0 # Command not necessary but good habit to signify no Abend.

Save the file in gedit. Now mark it as executable using:

chmod a+x ~/bin/

Next we need to add it to startup applications. Reference: How do I start applications automatically on login?

Note: You probably already have your slide show setup in startup applications. You will want to use BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.


You will want to test script when you create it and not wait a year to see if it works properly or not. Reference: Faking the date for a specific shell session


After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to down the road.

Compress files to save disk space

Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp (Copy) command with the tar command to uncompress the files. Reference: 23 tar Command Examples For Linux:

For example, we would change:

cp -R "$SpringDir"/. "$SlideShowDir"/


tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/

… and so on for the other seasons.

Setup variables for season start

Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).

Consider setting up Variables for start of season:


Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to “Meteorological” season starts instead of “Astronomical” start dates.

Then change these lines:

if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then

To this:

if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then

Top ToS
⇧ CPU frequency too high even with 'powersave' governor What does spool mean for printing?  ⇩