Files
dotfiles/.local/bin/station-bg-next

44 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2026-03-06 22:33:30 +00:00
#!/bin/bash
# Cycles through the background images available
BACKGROUNDS_PATH="$HOME/Tower/Library/Pictures/Wallpapers/3840x2160/"
CURRENT_BACKGROUND_LINK="$HOME/.local/state/station/background"
mapfile -d '' -t BACKGROUNDS < <(find -L "$BACKGROUNDS_PATH" -maxdepth 1 -type f -print0 2>/dev/null | sort -z)
TOTAL=${#BACKGROUNDS[@]}
if (( TOTAL == 0 )); then
notify-send "No background was found" -t 2000
pkill -x swaybg
setsid uwsm-app -- swaybg --color '#000000' >/dev/null 2>&1 &
else
# Get current background from symlink
if [[ -L $CURRENT_BACKGROUND_LINK ]]; then
CURRENT_BACKGROUND=$(readlink "$CURRENT_BACKGROUND_LINK")
else
# Default to first background if no symlink exists
CURRENT_BACKGROUND=""
fi
# Find current background index
INDEX=-1
for i in "${!BACKGROUNDS[@]}"; do
if [[ ${BACKGROUNDS[$i]} == $CURRENT_BACKGROUND ]]; then
INDEX=$i
break
fi
done
# Get next background (wrap around)
if (( INDEX == -1 )); then
# Use the first background when no match was found
NEW_BACKGROUND="${BACKGROUNDS[0]}"
else
NEXT_INDEX=$(((INDEX + 1) % TOTAL))
NEW_BACKGROUND="${BACKGROUNDS[$NEXT_INDEX]}"
fi
2026-03-08 19:37:53 +00:00
station-bg-set "$NEW_BACKGROUND"
2026-03-06 22:33:30 +00:00
fi