From 5a3373ab70f54b8f7a0f1c16b6a80dd4a8e87f1f Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 16 May 2023 21:19:00 +0200 Subject: [sway] build script to enable auto-changing wallpapers --- .config/sway/bin/wallpaper.sh | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 .config/sway/bin/wallpaper.sh (limited to '.config/sway/bin/wallpaper.sh') diff --git a/.config/sway/bin/wallpaper.sh b/.config/sway/bin/wallpaper.sh new file mode 100755 index 0000000..a035c03 --- /dev/null +++ b/.config/sway/bin/wallpaper.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +WALLPAPER_PATH="$HOME/Images/Wallpaper" +INTERVAL=600 + +while getopts 'p::t::' OPTION; do + case "$OPTION" in + p) + WALLPAPER_PATH="$OPTARG" + ;; + t) + INTERVAL="$OPTARG" + ;; + ?) + echo "Usage: {$0} [--path=] [--time=]" + exit 1 + ;; + esac +done + +RUNNING_PID=-1 +while true; do + # run swaybg + RANDOM_NUMBER=$(shuf -i 1-10 -n 1) + if [ $RANDOM_NUMBER -le 2 ]; then + swaybg -i "$(find "$WALLPAPER_PATH" -type f | shuf -n1)" -m fill & + else + swaybg -i "$(find "$WALLPAPER_PATH" -type f -not -path "*/hyper-pokemon/*" | shuf -n1)" -m fill & + fi + + # get pid of new spawned instance + NEW_PID=$! + + # wait until new instance of swaybg has booted up properly + sleep 5 + + # kill the previous process + # the new swaybg process takes its place automatically + kill $RUNNING_PID + + # set pid for next iteration + RUNNING_PID=$NEW_PID + + # wait $INTERVAL seconds + sleep $INTERVAL +done -- cgit v1.2.3