change the wallpaper-changer script to use a pid file

This commit is contained in:
smayzy 2025-07-01 16:11:39 +02:00
parent 1cb4b45de1
commit c1ef7c8ef8

View File

@ -1,6 +1,17 @@
#!/usr/bin/env bash
Wallpaper_DIR="/home/smayzy/wallpaper"
LOCKFILE="/tmp/wallpaper_changer.lock"
if [ -f "$LOCKFILE" ]; then
old_pid=$(cat "$LOCKFILE")
if ps -p "$old_pid" > /dev/null 2>&1; then
kill "$old_pid"
sleep 1
fi
fi
echo $$ > "$LOCKFILE"
set_wallpaper() {
local Wallpaper=$(find $Wallpaper_DIR | shuf -n 1)
@ -10,11 +21,12 @@ set_wallpaper() {
echo "preload = $Wallpaper" >> /home/smayzy/.config/hypr/hyprpaper.conf
echo "wallpaper = ,$Wallpaper" >> /home/smayzy/.config/hypr/hyprpaper.conf
# Restart hyprpaper
pkill hyprpaper 2>/dev/null
hyprpaper &
}
trap "rm -f $LOCKFILE" EXIT
while true; do
set_wallpaper
sleep 600