Skip to content

Instantly share code, notes, and snippets.

@jb-1980 jb-1980/seasons.sh
Last active Dec 17, 2018

Embed
What would you like to do?
Dynamic wallpaper directories for Ubuntu
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: modified from script given at: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir=$HOME/wallpapers/slideshow
SpringDir=$HOME/wallpapers/spring
SummerDir=$HOME/wallpapers/summer
FallDir=$HOME/wallpapers/fall
WinterDir=$HOME/wallpapers/winter
# Day of year that seasons start
Spring=$(date --date="March 21" '+%j')
Summer=$(date --date="June 21" '+%j')
Fall=$(date --date="Sep 21" '+%j')
Winter=$(date --date="Dec 21" '+%j')
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
# For days less than 100, the date function returns as 0XX, which is interpreted as an octal.
# This will force it to be a decimal and avoid the "value too great for base" error.
# Reference: https://stackoverflow.com/questions/12821715/convert-string-into-integer-in-bash-script
DOY=$((10#$DOY))
Spring=$((10#$Spring))
Summer=$((10#$Summer))
Fall=$((10#$Fall))
Winter=$((10#$Winter))
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
if ((DOY>="$Spring" && DOY<"$Summer")) ; then
ln -sfn "$SpringDir" "$SlideShowDir" # Spring has sprung!
elif ((DOY>="$Summer" && DOY<"$Fall")) ; then
ln -sfn "$SummerDir" "$SlideShowDir" # Hit the beach!
elif ((DOY>="$Fall" && DOY<"$Winter")) ; then
ln -sfn "$FallDir" "$SlideShowDir" # Rake those leaves!
else
ln -sfn "$WinterDir" "$SlideShowDir" # Shovel the snow!
fi
exit 0 # Command not necessary but good habit to signify no Abend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.