This assumes you are using Hyprland and have Hyprpaper installed.
Don't forget to update your WALLPAPER_DIR
path.
Also, I put the script in my .config/hypr
folder, you should put it where you keep your shell scripts.
#!/bin/bash
ATTEMPTS=0
MAX_NUM=10
FILES=()
WALLPAPER_DIR="/usr/share/backgrounds"
CURRENT_WALL=$(hyprctl --instance 0 hyprpaper listloaded)
WALLPAPER=""
while true; do
((ATTEMPTS++))
echo "Attempt #$ATTEMPTS"
if (( ATTEMPTS > MAX_NUM )); then
notify-send "Error: we tried to set the following files: ${FILES[*]}"
exit 1
fi
WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$(basename "$CURRENT_WALL")" | shuf -n 1)
if [[ -z "$WALLPAPER" ]]; then
notify-send "Error: No suitable wallpapers found."
exit 1
fi
MIME_TYPE=$(file --mime-type -b "$WALLPAPER")
if [[ ! "$MIME_TYPE" =~ ^image/ ]]; then
echo "$WALLPAPER - $MIME_TYPE"
FILES+=("$WALLPAPER")
notify-send "WARNING" "The selected file '$WALLPAPER' is not an image (MIME type: $MIME_TYPE)."
else
echo "Setting: $WALLPAPER"
# Apply the selected wallpaper
hyprctl --instance 0 hyprpaper reload ,"$WALLPAPER"
break
fi
done
chmod +x hyprpaper_refresh.sh
"custom/wallpaper": {
"format": "",
"on-click": "/bin/bash ~/.config/hypr/hypr_refresh.sh"
},
crontab -e
*/5 * * * * ~/.config/hypr/hypr_refresh.sh >> ~/crontab_log.txt