Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created August 28, 2020 10:40
Show Gist options
  • Save rawiriblundell/2f4712037b2a06155a02a37878ab0c5a to your computer and use it in GitHub Desktop.
Save rawiriblundell/2f4712037b2a06155a02a37878ab0c5a to your computer and use it in GitHub Desktop.
A script I modified for someone to randomise their Cinnamon wallpaper
#!/bin/bash
# Script to set a per workspace desktop background in Cinnamon.
# Save as ~/bin/workspace_backgrounds_switcher.sh or
# ~/.local/bin/workspace_backgrounds_switcher.sh and make executable
# Add an entry in startup applications to launch the script on start-up.
# Set path to background images
background_path=/usr/share/backgrounds/linuxmint/
# Select a random background from the aforementioned path
random_background=$(shuf -e "${background_path}/*" -n 1)
# Main script starts here
# Check for existing instances and kill them leaving current instance running
for PID in $(pidof -o %PPID -x "${0##*/}"); do
(( "${PID}" != "$$" )) && kill -9 "${PID}"
done
# Monitor for workspace changes and set the background on change.
while read -r; do
# Get the current background image
current_background=$(gsettings get org.cinnamon.desktop.background picture-uri)
# Ensure that our randomly selected background isn't currently in use
while [[ "${current_background//\'/}" = "${random_background}" ]]; do
random_background=$(shuf -e "${background_path}" -n 1)
done
gsettings set org.cinnamon.desktop.background picture-uri "file://${random_background}"
done < <(xprop -root -spy _NET_CURRENT_DESKTOP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment