summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-23 11:24:36 +0300
committerPaul Buetow <paul@buetow.org>2026-05-23 11:24:36 +0300
commit8eb4c58043eaffad13f09e5eb69d884a1b073657 (patch)
treeac11fb31d73a13d217dbfa3e3e9dfb5687b63a7e /scripts
parent95e03c30b20402fd44ec8449aaee7d6712609ee8 (diff)
Add random GNOME wallpaper timer via systemd user units
Diffstat (limited to 'scripts')
-rw-r--r--scripts/random-wallpaper.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/random-wallpaper.sh b/scripts/random-wallpaper.sh
new file mode 100644
index 0000000..03fb160
--- /dev/null
+++ b/scripts/random-wallpaper.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Randomly sets a GNOME desktop wallpaper from image files in a given directory.
+
+WALLPAPER_DIR="$HOME/Pictures/Pixel7ProDCIM/Irregular Ninja/irregular.ninja"
+
+if [ ! -d "$WALLPAPER_DIR" ]; then
+ printf 'Directory not found: %s\n' "$WALLPAPER_DIR" >&2
+ exit 1
+fi
+
+# Pick a random image file (common extensions)
+IMAGE=$(find "$WALLPAPER_DIR" -maxdepth 1 -type f \
+ \( \
+ -iname '*.jpg' -o \
+ -iname '*.jpeg' -o \
+ -iname '*.png' -o \
+ -iname '*.bmp' -o \
+ -iname '*.webp' -o \
+ -iname '*.gif' \
+ \) | sort -R | head -n 1)
+
+if [ -z "$IMAGE" ]; then
+ printf 'No images found in %s\n' "$WALLPAPER_DIR" >&2
+ exit 1
+fi
+
+# GNOME Shell caches wallpaper textures keyed by URI.
+# If the path is always the same, Shell won't reload even when the file
+# contents change. Use a unique filename on every run so the URI changes
+# and Shell is forced to load the new image.
+CLEAN_DIR="$HOME/.local/share/wallpapers"
+UNIQUE="random-wallpaper-$(date +%s)"
+CLEAN_PATH="$CLEAN_DIR/$UNIQUE.jpg"
+
+mkdir -p "$CLEAN_DIR"
+cp "$IMAGE" "$CLEAN_PATH"
+
+# Clean up old copies to avoid filling the directory
+# Keep the last 5 wallpapers around
+ls -1t "$CLEAN_DIR"/random-wallpaper-*.jpg 2> /dev/null | sed -n '6,$p' | xargs -r rm -f
+
+# dconf-service on Fedora 50 has a bug where gsettings set keeps changes in
+# memory but never syncs them to the on-disk database. GNOME Shell reads
+# directly from disk, so it never sees wallpaper changes made with gsettings.
+# Writing via dconf write bypasses the buggy service and hits the database
+# directly, making GNOME Shell pick up the change immediately.
+dconf write /org/gnome/desktop/background/picture-uri "'file://$CLEAN_PATH'"
+dconf write /org/gnome/desktop/background/picture-uri-dark "'file://$CLEAN_PATH'"
+
+# Show me what was set
+printf 'Set wallpaper to: %s (copied from %s)\n' "$CLEAN_PATH" "$IMAGE"