Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions pages/Hypr Ecosystem/hyprpaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,40 @@ You can also use this simple `reload` functionality to randomize your wallpaper.

```bash
#!/usr/bin/env bash

WALLPAPER_DIR="$HOME/wallpapers/"
CURRENT_WALL=$(hyprctl hyprpaper listloaded)

# Get a random wallpaper that is not the current one
WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$(basename "$CURRENT_WALL")" | shuf -n 1)

# Apply the selected wallpaper
hyprctl hyprpaper reload ,"$WALLPAPER"
ATTEMPTS=0
MAX_NUM=10
FILES=()
WALLPAPER_DIR="/usr/share/backgrounds"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks weird. Should be left as the user's home.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound feedback, I will get that updated when I can.

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
```

For a multiple-monitor setup, you can use this modified script that randomizes the wallpaper of your currently focused monitor:
Expand Down