Last active
January 2, 2018 06:29
-
-
Save ericc3141/1e8dbef348b3e07c2903bab10de70d35 to your computer and use it in GitHub Desktop.
Simple multi-desktop wallpaper changer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple multi-desktop wallpaper changer | |
# Place desired wallpapers in same directory, name by desktop number | |
# 0.png for first desktop, 1.png on second, etc | |
# Requires xprop, wmctrl, feh | |
# Usage: changeDesktop.sh [deskop] [action] | |
# desktop desktop number, or p/n for previous/next | |
# action m- Move active window to new desktop | |
# w- Wrap between first and last desktop | |
# Exit if no arguments | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: changeDesktop.sh [deskop] [-m]" | |
exit 1 | |
fi | |
# Simplified argument parsing | |
if [ $# = "2" ] && [[ $2 == "-"* ]];then | |
# Move window if necessary | |
if [[ $2 == *"m"* ]];then | |
echo Move active | |
MOVE=1 | |
fi | |
if [[ $2 == *"w"* ]];then | |
echo Wrap around | |
WRAP=1 | |
fi | |
fi | |
# To be honest | |
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Gives the last two characters from xprop query | |
# Using to get numbers, hopefully no more than 2 digits | |
function getProp { | |
local prop=$(xprop -root $1) | |
echo ${prop:(-2)} | |
} | |
CURRDESK=$(getProp _NET_CURRENT_DESKTOP) | |
NUMDESKS=$(getProp _NET_NUMBER_OF_DESKTOPS) | |
echo On desktop $CURRDESK, $NUMDESKS total | |
# Next desktop | |
if [[ $1 = "n" && ( ! -z $WRAP || $CURRDESK -lt $(($NUMDESKS-1)) ) ]]; then | |
let "CURRDESK = ($CURRDESK + 1) % $NUMDESKS" | |
# Previous desktop | |
elif [[ $1 = "p" && ( ! -z $WRAP || $CURRDESK -gt "0" ) ]]; then | |
let "CURRDESK = ($CURRDESK - 1 + $NUMDESKS) % $NUMDESKS" | |
# Numbered desktop | |
elif [[ $1 != "p" && $1 != "n" ]]; then | |
echo To $1 | |
let "CURRDESK = $1" | |
fi | |
echo Will switch to desktop $CURRDESK | |
# Set new background | |
feh --bg-fill $(echo $DIR"/"$CURRDESK".png") | |
# Move active window if necessary | |
if [ ! -z $MOVE ]; then | |
echo Moving active | |
wmctrl -r :ACTIVE: -t $CURRDESK | |
fi | |
# Switch desktop | |
wmctrl -s $CURRDESK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script to enable different wallpapers on each workspace and monitor. | |
# Written by damo <[email protected]> November 2015 | |
# | |
# To run while logged in, add "wallpapersd &" to your autostart | |
# | |
# REQUIRES: 'feh' | |
############################################################################### | |
# To be honest$ | |
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within$ | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
FEH_CMD="feh --bg-fill" # edit this, or wallpapers.cfg, to use a different feh command | |
NUM_DESKTOPS=$(xprop -root _NET_NUMBER_OF_DESKTOPS | tail -c -2) | |
xprop -root -spy _NET_CURRENT_DESKTOP | ( # <-- this is the watching process | |
while read -r;do | |
CURR_DESKTOP=${REPLY:${#REPLY}-1:1} | |
echo $CURR_DESKTOP | |
feh --bg-fill $(echo $DIR"/"$CURR_DESKTOP".png") | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment