Files
nixos/Droidnix/assets/traveldroid/Wallpapers/set-wallpapers-at-logon.sh
T
2026-03-29 12:40:31 +00:00

35 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
PICTURES_DIR="$HOME/Wallpapers/pictures"
# -----------------------------
# Get list of images
# -----------------------------
mapfile -t IMAGES < <(find "$PICTURES_DIR" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \))
if [ "${#IMAGES[@]}" -eq 0 ]; then
echo "No images found in $PICTURES_DIR"
exit 1
fi
# -----------------------------
# Start swww daemon if not running
# -----------------------------
if ! pgrep -x swww > /dev/null; then
echo "Starting swww daemon..."
swww daemon &
sleep 1 # Give daemon time to start
fi
# -----------------------------
# Set a random wallpaper per workspace
# -----------------------------
WORKSPACES=$(hyprctl workspaces -j | jq -r '.[].id')
for ws in $WORKSPACES; do
RAND_IMAGE="${IMAGES[RANDOM % ${#IMAGES[@]}]}"
echo "Setting wallpaper for workspace $ws: $RAND_IMAGE"
# Each workspace gets its own namespace
swww img "$RAND_IMAGE" --resize fit --transition-type random --namespace "$ws"
done