diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-23 11:24:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-23 11:24:36 +0300 |
| commit | 8eb4c58043eaffad13f09e5eb69d884a1b073657 (patch) | |
| tree | ac11fb31d73a13d217dbfa3e3e9dfb5687b63a7e | |
| parent | 95e03c30b20402fd44ec8449aaee7d6712609ee8 (diff) | |
Add random GNOME wallpaper timer via systemd user units
| -rw-r--r-- | Rexfile | 24 | ||||
| -rw-r--r-- | scripts/random-wallpaper.sh | 51 | ||||
| -rw-r--r-- | systemd-user/random-wallpaper.service | 6 | ||||
| -rw-r--r-- | systemd-user/random-wallpaper.timer | 9 |
4 files changed, 90 insertions, 0 deletions
@@ -376,6 +376,30 @@ task 'home_quickedit', sub { } }; +desc 'Install systemd user units'; +task 'home_systemd_user', sub { + my $dst_dir = "$HOME/.config/systemd/user"; + + file $dst_dir, + ensure => 'directory', + mode => '0700'; + + for my $file ( glob "${DOT}/systemd-user/*" ) { + file "$dst_dir/" . basename($file), + ensure => 'present', + source => $file, + mode => '0640'; + } + + # Reload systemd user daemon to pick up any new or changed units. + Rex::Logger::info('Reloading systemd user daemon'); + run 'systemctl --user daemon-reload'; + + # Enable the random-wallpaper timer so it starts on login. + Rex::Logger::info('Enabling random-wallpaper.timer'); + run 'systemctl --user enable random-wallpaper.timer'; +}; + desc 'Install all my ~ files'; task 'home', sub { require Rex::TaskList; 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" diff --git a/systemd-user/random-wallpaper.service b/systemd-user/random-wallpaper.service new file mode 100644 index 0000000..f82af6c --- /dev/null +++ b/systemd-user/random-wallpaper.service @@ -0,0 +1,6 @@ +[Unit] +Description=Set random GNOME wallpaper from image directory + +[Service] +Type=oneshot +ExecStart=%h/scripts/random-wallpaper.sh diff --git a/systemd-user/random-wallpaper.timer b/systemd-user/random-wallpaper.timer new file mode 100644 index 0000000..d3aef0a --- /dev/null +++ b/systemd-user/random-wallpaper.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Set random GNOME wallpaper once per hour + +[Timer] +OnCalendar=hourly +Persistent=true + +[Install] +WantedBy=timers.target |
