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

vsantos revised this gist 1 week ago · 54fad60

1 file changed, 64 insertions

wallpaper.sh (file created)
@@ -0,0 +1,64 @@
1 + #!/usr/bin/env bash
2 +
3 + # ==================================================
4 + # CAMBIO AUTOMÁTICO DE FONDO DE PANTALLA
5 + # ==================================================
6 +
7 + WALLPAPER_DIR="$HOME/.config/backgrounds"
8 + OUTPUT="DP-4"
9 + INTERVAL=600
10 +
11 + # Buscar imágenes disponibles
12 + mapfile -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
23 + if [ "${#WALLPAPERS[@]}" -eq 0 ]; then
24 + echo "No se han encontrado imágenes en $WALLPAPER_DIR"
25 + exit 1
26 + fi
27 +
28 + CURRENT_PID=""
29 +
30 + # Limpiar al cerrar el script
31 + cleanup() {
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 +
38 + trap cleanup EXIT INT TERM
39 +
40 + # Bucle principal
41 + while 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 +
64 + done