dotfiles/scripts/dynamic-wallpaper.sh

41 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# get todays md5sum and extract first 2 chars then convert it to base 10
2022-01-25 15:00:57 +01:00
randomizer=$(cat ~/.wallpaper_randomizer)
today=$(date +%x)
todays_hash=$(echo "$randomizer $today" | md5sum | cut -c 1-2)
base10=$(echo $((0x$todays_hash)) | bc)
echo "base 10 ${base10}"
# calculate the index for the wallpaper set: base10 % num_of_dirs
dirs=$(find ~/Pictures/Wallpapers/time-based/* -maxdepth 1 -type d)
num_of_dirs=$(echo "${dirs}" | wc -l)
index=$(echo "${base10} % ${num_of_dirs} + 1" | bc)
wallpaper_set=$(echo "${dirs}"| sed -n "${index}p")
# get the file path based on the current hour of the day
num=$(date +%-H)
image="$wallpaper_set/$num"
if [[ -f "${image}.png" ]]; then
format="png"
elif [[ -f "${image}.jpg" ]]; then
format="jpg"
else
notify-send "Could not find any image for $image"
fi
path="$wallpaper_set/$num.$format"
echo "path: $path"
2021-08-22 10:41:54 +02:00
actual_file=$(readlink -f $path)
2021-08-22 10:28:28 +02:00
set_wallpaper() {
wal -st -i $1 --backend=haishoku
python3 ~/scripts/misc/adjust_terminal_colors.py rgb 0.5
~/scripts/misc/restart_dunst.sh
xrdb ~/.Xresources
2021-08-22 10:28:28 +02:00
}
# if the current wallpaper is different than the previous one, set it
2022-01-25 15:00:57 +01:00
[[ $(< ~/.last_wallpaper_path) != "$actual_file" || $1 ]] && set_wallpaper $actual_file
2021-08-22 10:28:28 +02:00
echo "$actual_file" > ~/.last_wallpaper_path