Issue with wallpaper changing while hovering over names in Rofi — where am I going wrong?
0
votes
0
answers
36
views
I’ve written a script to change my wallpaper with Rofi, but I’m having a problem. While I hover over the wallpaper names in the rofi menu, the wallpaper is not changing dynamically for like a temporary preview (as I expect). By the way, I want the wallpaper to only change after I select the one I want and not during browsing.
Here's the script I’m using:
#!/bin/bash
WALLPAPER_DIR="$HOME/Pictures/Wallpapers"
# Function to format wallpaper names for display
format_name() {
basename "$1" | sed -E 's/[0-9]+[kK]?[- ]?[0-9]*[a-z]*//g; s/-/ /g; s/\.(jpg|png|jpeg)$//I; s/\b([a-z])/\u\1/g; s/\s+/ /g; s/^\s+|\s+$//g'
}
# Get list of wallpapers and format them
mapfile -t wallpapers < <(find "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.jpeg" \))
formatted_names=()
for wp in "${wallpapers[@]}"; do
formatted_names+=("$(format_name "$wp")")
done
# Store current wallpaper
current_wallpaper=$(grep 'feh --bg-scale' ~/.fehbg | cut -d "'" -f2)
# Let rofi show and capture the selection live
selection=$(printf "%s\n" "${formatted_names[@]}" | rofi -dmenu -i -p "Select Wallpaper" -format "s" -monitor-changes | while read -r selected_name; do
for wp in "${wallpapers[@]}"; do
if [ "$(format_name "$wp")" == "$selected_name" ]; then
# Change wallpaper temporarily as user browses
feh --bg-scale "$wp"
break
fi
done
done)
# Revert to previous wallpaper if no final selection
if [ -z "$selection" ]; then
[ -n "$current_wallpaper" ] && feh --bg-scale "$current_wallpaper"
fi
I’ve tried some solutions, but I’m not sure where I’m going wrong. Is there a simple way to the wallpaper from changing on temporary basis until I make a final selection? Any guidance would be appreciated... Oh I am using Arch (btw). :v
Asked by DarKnightz
(61 rep)
Feb 28, 2025, 10:01 PM