Code: Select all
#!/bin/bash
#---- HOW TO -- read me to get this started
# change the values in USERSETTINGS so that
# WALLPAPER_ROOT is a directory with subdirectories with images only
# and WALLPAPER_SETS names those subdirectories you want to associate with your work spaces
# DELAY can be set optional for different timeouts
# run the script manually - if each workspace rotates its associated images
# set is as a start scrip (look for startup in mint menu)
# log of and on tho get it working
#---- USERSETTINGS ---- user defined settings to be changed
#full path to images directory; do NOT use ~ here...
WALLPAPER_ROOT="/home/hans/Wallpaper/"
#subsets of wallpapers per workspace
WALLPAPER_SETS=("wood" "mountain" "sea")
#circle every xxx in seconds (initial 300 = 5 minutes
DELAY=300
#---- functions to be modified only if you want to change the overall behaviour
#set the wallpaper based on current desktop and timestamp
setWallpaper() {
pics=()
echo scanning "$CURRENT_WALLPAPER_SET"
# collect pictures in current wallpaper set
for file in "$CURRENT_WALLPAPER_SET"/*; do
pics=("${pics[@]}" "$file")
done
total=${#pics[@]}
# pictures must not be empty
if [ "$total" != 0 ]; then
bySeconds=$(bc <<< $(date "+%s/$DELAY"%"$total"))
wallpaper=${pics["$bySeconds"]}
gsettings set org.gnome.desktop.background picture-uri file:///"$wallpaper"
fi
}
# loop forever for time based image rotation
loopImages() {
while [[ 1 -eq 1 ]]; do
setWallpaper
sleep "$DELAY"
done
}
# set initial values
init() {
#set initial wallpaper folder
export CURRENT_WALLPAPER_SET=$WALLPAPER_ROOT${WALLPAPER_SETS[0]}
# set the desktop names
WALLPAPER_SETS_STR=$(printf "'%s', " ${WALLPAPER_SETS[*]})
WALLPAPER_SETS_STR="[$(echo ${WALLPAPER_SETS_STR} | rev | cut -c 2- | rev)]"
gsettings set org.cinnamon.desktop.wm.preferences workspace-names "${WALLPAPER_SETS_STR}"
gsettings set org.cinnamon number-workspaces ${#WALLPAPER_SETS[@]}
}
#---- MAIN ---------------------------------------------------------------------
init
# onChange:
xprop -root -spy _NET_CURRENT_DESKTOP | while read -r; do
if [[ "$!" != "" ]]; then kill $!; fi # stop the timed loop
# get the desktop number:
CURR_DESKTOP_NUM="${REPLY: -1}"
CURRENT_WALLPAPER_SET=$WALLPAPER_ROOT${WALLPAPER_SETS[CURR_DESKTOP_NUM]}
loopImages& # restart the timed loop
done
The script works fine for me, I just have the impression, that sometimes shutting down taks some extra time and I am not sure if the inner loop (loopImages) is responsible for this.
So one question is - what would be a good way to determine if this script delays shuidown due a respectful waiting of the system for the process to stop
The other question is (asuming that the scrip is delaying the shutdown) how to detect a requesting shutdown signal and speed up the stop (probably hanging around in "sleep")