Script to change background depending on workspace 17.10


#1

Since mate-desktop doesn’t support this, I’ve borrowed this script from damo and changed it to work with Mate Desktop.
The script monitors root window for xwindow property _NET_CURRENT_DESKTOP change and then changes background depending on which workspace is active.
Save the script with the exact filename “wallpapersd” (without the quotes). Make executable (or chmod +x) and run.

[code]#!/bin/bash

Script to enable different wallpapers on each workspace and monitor with Openbox

Written by damo [email protected] November 2015

Modified for mate desktop by misko_2083 November 2017

When first run, the script writes a configuration file template. The user can

then edit this and add the image filepaths.

To run while logged in, add “wallpapersd &” to your autostart

REQUIRES: ‘pluma’

###############################################################################

WALLS_FILE="$HOME/.config/wallpapers.cfg"
FEH_CMD=" gsettings set org.mate.background picture-filename" # edit this, or wallpapers.cfg, to use a different command

TXT="# Add filepaths to the images to be set as backgrounds on each workspace.

You can have an image set for each monitor.

Commands should be in the form:

$FEH_CMD ‘path/to/image1(monitor 1)’ ‘path/to/image2(monitor 2)’ etc

You may want to disable background transitioning effect with dconf-editor

###########################################################################"

USAGE="USAGE:

wallpapersd & Runs the ‘daemon’ to set per-workspace backgrounds.
First run will open wallpapers.cfg, which has instructions and feh settings.

–config Open wallpapers.cfg for editing

-h,–help This help
"

case “$1” in
-h|–help ) echo -e “\n$USAGE”
exit
;;
–config ) if [[ -f $WALLS_FILE ]] &>/dev/null;then
echo -e “\n Open wallpapers.cfg for editing?\n (wallpapersd needs to be restarted afterwards) y|N”
read -srn1 RET
case $RET in
n|N ) exit;;
y|Y ) pluma “$WALLS_FILE” & # open cfg file for editing
killall wallpapersd
exit
;;
* ) exit
;;
esac
else
echo -e " No ~/.config/wallpapers.cfg found\n Run wallpapersd first? Y|n?"
read -srn1 ANS
case $ANS in
n|N ) exit
;;
* ) wallpapersd 2>/dev/null & # run app to generate cfg template
pluma “$WALLS_FILE” & # open cfg file for editing
;;
esac
fi
;;
esac

if [[ ! -f $WALLS_FILE ]];then
echo -e “$TXT\n” > “$WALLS_FILE”
NUM_DESKTOPS=$(xprop -root NET_NUMBER_OF_DESKTOPS)
NUM_DESKTOPS=${NUM_DESKTOPS:(-1)}
for (( i=0; i < $NUM_DESKTOPS; i++ ));do
echo "[DESKTOP
$i] $FEH_CMD " >> “$WALLS_FILE”
done
xdg-open “$WALLS_FILE” # open cfg file for editing. Script must be restarted afterwards.
exit
else
xev -root -event property | # <-- this is the watching process
while IFS=$’,’ read -a W;do
if [[ “${W[0]}” =~ ‘_NET_CURRENT_DESKTOP’ ]]; then
CURR_DESKTOP=$(xprop -root NET_CURRENT_DESKTOP)
CURR_DESKTOP=${CURR_DESKTOP:(-1)}
while read DTOP CMD;do
VAL="[DESKTOP
$CURR_DESKTOP]"
if [[ “$DTOP” = “$VAL” ]];then
eval $CMD
fi
done < “$WALLS_FILE”
fi
W=()
done
fi[/code]
On first run it creates a configuration file /home/username/.config/wallpapers.cfg and opens in pluma. You need to add wallpapers like this example:

[DESKTOP_0] gsettings set org.mate.background picture-filename /usr/share/backgrounds/ubuntu-mate-artful/the-moon-and-ubuntu-mate.jpg [DESKTOP_1] gsettings set org.mate.background picture-filename /usr/share/backgrounds/ubuntu-mate-artful/Ubuntu-MATE-Moon.jpg [DESKTOP_2] gsettings set org.mate.background picture-filename /usr/share/backgrounds/ubuntu-mate-artful/Ubuntu-MATE-Northern-Lights.jpg [DESKTOP_3] gsettings set org.mate.background picture-filename /usr/share/backgrounds/ubuntu-mate-artful/Ubuntu-MATE-Sea.jpg
Save the file and start wallpapersd again and toggle workspaces.
Background change could be a little faster if you disable background-fade effect. You can do that with dconf-editor and navigate to /org/mate/desktop/background/background-fade to disable.