xkcd-clock/bg_setter.sh

56 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
#
# This script is licensed under MIT License
# You are encouraged to learn from it by tinkering.
#
# Artwork used for this project was originally taken from https://xkcd.com/now
# and is licensed under CC BY-NC 2.5 and I decided to preserve that license
# for their upscaled versions.
#
# Upscaling original artwork was done using Upscaler by Hari Rana. Upscaler is a
# frontend for "Real-ESRGAN ncnn Vulkan" project which is a neural engine for
# restoring old images to higher quality using Vulkan.
# Hari Rana: https://theevilskeleton.gitlab.io/
# Upscaler: https://gitlab.com/TheEvilSkeleton/Upscaler
# Real-ESRGAN ncnn Vulkan: https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan
### How to use this
#
## Set this script to run minutely as unprivileged user (not root)
# below path is an example and you may need to change it for it to work right
# This example assumes that you extracted the tarball or pulled the git repo to
# ~/Pictures/Wallpapers
# * * * * * $HOME/Pictures/Wallpapers/xkcd-clock/wallpaper_setter.sh
#
# You might have issues like stretched, squised or tiled image
# below commands may help solving those issues
# GNOME
# gsettings set org.gnome.desktop.background picture-options "scaled" 2> /dev/null
# locate where the images are
BG_REPO=$(dirname -- $(readlink -fn -- "$0"))
# Find out which image should be set as wallpaper
TimeZone='Pacific/Fiji' # I don't care where you are. Don't change this.
HOUR=$(TZ=$TimeZone date +%H) #; echo $HOUR
MINUTE=$(TZ=$TimeZone date +%M) #; echo $MINUTE
Remainder=$(( $MINUTE % 15 )) #; echo $Remainder
MINUTE=$(( $MINUTE - $Remainder )) #; echo $MINUTE
# If Minute is single digit at this point, add a zero before it to match file
# naming scheme
if [ $MINUTE -le 9 ];
then
MINUTE=`echo 0$MINUTE`
fi
# Finally generate new background's complete path
BG_PATH="$BG_REPO/$(echo $HOUR)h$(echo $MINUTE)m.png" #; echo $BG_PATH
# Set the new background
# GNOME
# There are 2 commands because GNOME can set different wallpapers for light
# and dark themes.
gsettings set org.gnome.desktop.background picture-uri "$BG_PATH" 2> /dev/null
gsettings set org.gnome.desktop.background picture-uri-dark "$BG_PATH" 2> /dev/null