vsantos

vsantos / wallpaper.sh

Last active 1 week ago

Like 0

Wallpaper para usar con Niri para que cada 10 minutos se modifique en fondo de pantalla

wallpaper.sh Raw
1#!/usr/bin/env bash
2
3# ==================================================
4# CAMBIO AUTOMÁTICO DE FONDO DE PANTALLA
5# ==================================================
6
7WALLPAPER_DIR="$HOME/.config/backgrounds"
8OUTPUT="DP-4"
9INTERVAL=600
10
11# Buscar imágenes disponibles
12mapfile -d '' WALLPAPERS < <(
13 find "$WALLPAPER_DIR" -type f \
14 \( -iname '*.jpg' \
15 -o -iname '*.jpeg' \
16 -o -iname '*.png' \
17 -o -iname '*.webp' \
18 -o -iname '*.bmp' \) \
19 -print0
20)
21
22# Comprobar que existen imágenes
23if [ "${#WALLPAPERS[@]}" -eq 0 ]; then
24 echo "No se han encontrado imágenes en $WALLPAPER_DIR"
25 exit 1
26fi
27
28CURRENT_PID=""
29
30# Limpiar al cerrar el script
31cleanup() {
32 if [ -n "$CURRENT_PID" ]; then
33 kill "$CURRENT_PID" 2>/dev/null || true
34 wait "$CURRENT_PID" 2>/dev/null || true
35 fi
36}
37
38trap cleanup EXIT INT TERM
39
40# Bucle principal
41while true; do
42
43 # Seleccionar una imagen aleatoria
44 INDEX=$(shuf -i 0-$((${#WALLPAPERS[@]} - 1)) -n 1)
45 IMAGE="${WALLPAPERS[$INDEX]}"
46
47 # echo "Nuevo fondo: $IMAGE"
48
49 # Iniciar el nuevo fondo
50 swaybg -o "$OUTPUT" -i "$IMAGE" -m fill &
51 NEW_PID=$!
52
53 # Cerrar el fondo anterior
54 if [ -n "$CURRENT_PID" ]; then
55 kill "$CURRENT_PID" 2>/dev/null || true
56 wait "$CURRENT_PID" 2>/dev/null || true
57 fi
58
59 CURRENT_PID="$NEW_PID"
60
61 # Esperar 10 minutos
62 sleep "$INTERVAL"
63
64done

Comments 0

Log in to leave a comment