1. Randomizes the wallpaper from a directory (very, very rudimentary)
2. Changes the panel background colour to match a colour-sampled section of the wallpaper below the panel
3. Fades the panel colour from the old wallpaper's colour-sample to the new wallpaper's colour sample.
Clearly in some ways similar to wlllpapoz that we have in the repos, but there seem to be significant diffs, both positive and negative.
Code: Select all
#!/bin/bash
###
### Description: Randomly cycles the wallpaper from a collection of wallpapers in a directory
### while changing the backgound colour of the panel to match the average colour
### of the sampled image below the panel; as well as gradually stepping between
### the sampled colours of the old a new wallpapers to create a fading effect.
###
### Requires: imagemagick
###
### Setup: For the panel that you want affected:
### Appearance >> Style = Solid Color (background-style)
### Appearance >> Alpha = 75 (adjust to taste) (background-alpha)
### Appearance >> Color = #FFFFFF (so to create the xfconf property) (background-color)
###
### To get the required configurable values:
### DEBUG -> whether you want debug information displayed. Useful if
### running this script from a terminal to see what is
### avtually happening
### PANEL -> right-click the Panel and select Panel >> Panel Preferences
### the panel number will be shown
### PANEL_DIMS -> this is the width of the panel x the height of the panel +
### the coordinates of the top left corner
### (this box is used to sample the image for colour-matching)
### F -> the factor to dim the panel by. The maximum is 257 which is the average
### colour below the panel. 128 is used to create a dimmed version
### of the average colour. (valid = 0 to 257)
### NUM_STEPS -> the number of fade steps to get from the average colour of
### the previous image to the average colour of the new image
### This creates the fading effect
### iDIR -> The path to the directory that holds the images you want to cycle
### xfIMAGE -> the xfconf property specific to your system that holds the path
### and name of the current background image. To determine it,
### run "xfconf-query -c xfce4-desktop -m" in a terminal window
### and manually change the wallpaper. The location will be
### displayed in the terminal window
###
### Make sure that you make this script executable
### chmod +x /path/to/this/script
###
### Automation: Create a new user crontab entry "crontab -e" that looks like this:
### */5 * * * * /path/to/this/script
###
### The /5 indicates every 5 minutes. To have the wallpaper change every 15 minutes,
### use: */15
################################################################################################
# START OF CONFIGURABLE PARAMETERS
################################################################################################
# debug (change to 1 for debug output)
DEBUG=1
# the panel to affect (must match xfconf panel numbering)
PANEL="1"
[ $DEBUG -eq 1 ] && echo "Panel = "$PANEL
# the panel dimensions (for image sampling)
PANEL_DIMS="1366x24+0+0"
[ $DEBUG -eq 1 ] && echo "Panel Dimensions = "$PANEL_DIMS
# the factor to multiply by (257 is the max - this darkens from the average to give a more tint look)
F=128
[ $DEBUG -eq 1 ] && echo "factor = "$F
# the number of steps for fading effect
NUM_STEPS=10
# directory to choose images from
iDIR="/home/toz/Downloads/1366x768"
[ $DEBUG -eq 1 ] && echo "Image directory = "$iDIR
# xfconf image location
xfIMAGE="/backdrop/screen0/monitorLVDS1/workspace0/last-image"
[ $DEBUG -eq 1 ] && echo "xfconf last-image location = "$xfIMAGE
################################################################################################
# END OF CONFIGURABLE PARAMETERS
################################################################################################
# set environment variables (for cron usage) - tested under Arch Linux & Xubuntu 15.04
dbus_session_address=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep xfwm4)/environ | sed 's/^DBUS_SESSION_BUS_ADDRESS=//')
display=$(grep -z DISPLAY /proc/$(pgrep xfwm4)/environ | sed 's/^DISPLAY=//')
export DBUS_SESSION_BUS_ADDRESS="$dbus_session_address"
export DISPLAY="$display"
############### PRE
# the base wallpaper file location
OLD_WALL="$(xfconf-query -c xfce4-desktop -p $xfIMAGE)"
[ $DEBUG -eq 1 ] && echo "Old Wallpaper = "$OLD_WALL
# get the average colour of the area under the panel (assumes panel height of 24 and screen width of 1366)
# edit: 1366x24+0+0 to match panel geometry
# edit: /home/toz/.config/backdrop-randomizer.jpg to point to background image
_ans=$(convert -extract $PANEL_DIMS "$OLD_WALL" -scale 1x1\! -format '%[pixel:s]' info:-)
_ans2=$(echo $_ans | sed -e 's/srgb(//' | sed -e 's/)//' | sed -e 's/,/ /g')
_RED=$(echo $_ans2 | cut -d' ' -f1)
_GREEN=$(echo $_ans2 | cut -d' ' -f2)
_BLUE=$(echo $_ans2 | cut -d' ' -f3)
[ $DEBUG -eq 1 ] && echo " _ans = "$_ans
[ $DEBUG -eq 1 ] && echo " _ans2 = "$_ans2
[ $DEBUG -eq 1 ] && echo " _RED = "$_RED
[ $DEBUG -eq 1 ] && echo " _GREEN = "$_GREEN
[ $DEBUG -eq 1 ] && echo " _BLUE = "$_BLUE
# mutliply by factor to get correct xfconf values
let _aRED=$_RED*$F
let _aGREEN=$_GREEN*$F
let _aBLUE=$_BLUE*$F
[ $DEBUG -eq 1 ] && echo " _aRED = "$_aRED
[ $DEBUG -eq 1 ] && echo " _aGREEN = "$_aGREEN
[ $DEBUG -eq 1 ] && echo " _aBLUE = "$_aBLUE
############### PRE
############### Change the wallpaper
# randomize the image (not a true randomizer)
NEW_WALL="$(shuf -n1 -e $iDIR/*)"
[ $DEBUG -eq 1 ] && echo "Changing wallpaper....."
xfconf-query -c xfce4-desktop -p $xfIMAGE -s "$NEW_WALL"
# slight delay to allow wallpaper to load
sleep 0.1
####################################
############### POST
# the base wallpaper file location
NEW_WALL="$(xfconf-query -c xfce4-desktop -p $xfIMAGE)"
[ $DEBUG -eq 1 ] && echo "New Wallpaper = "$NEW_WALL
# get the average colour of the area under the panel (assumes panel height of 24 and screen width of 1366)
# edit: 1366x24+0+0 to match panel geometry
# edit: /home/toz/.config/backdrop-randomizer.jpg to point to background image
ans=$(convert -extract $PANEL_DIMS "$NEW_WALL" -scale 1x1\! -format '%[pixel:s]' info:-)
ans2=$(echo $ans | sed -e 's/srgb(//' | sed -e 's/)//' | sed -e 's/,/ /g')
RED=$(echo $ans2 | cut -d' ' -f1)
GREEN=$(echo $ans2 | cut -d' ' -f2)
BLUE=$(echo $ans2 | cut -d' ' -f3)
[ $DEBUG -eq 1 ] && echo " ans = "$ans
[ $DEBUG -eq 1 ] && echo " ans2 = "$ans2
[ $DEBUG -eq 1 ] && echo " RED = "$RED
[ $DEBUG -eq 1 ] && echo " GREEN = "$GREEN
[ $DEBUG -eq 1 ] && echo " BLUE = "$BLUE
# mutliply by factor to get correct xfconf values
let aRED=$RED*$F
let aGREEN=$GREEN*$F
let aBLUE=$BLUE*$F
[ $DEBUG -eq 1 ] && echo " aRED = "$aRED
[ $DEBUG -eq 1 ] && echo " aGREEN = "$aGREEN
[ $DEBUG -eq 1 ] && echo " aBLUE = "$aBLUE
############### POST
# set the panel background colour
[ $DEBUG -eq 1 ] && echo "Adjusting Panel #$PANEL....."
# get the differences
let rDIFF=($aRED-$_aRED)
let gDIFF=($aGREEN-$_aGREEN)
let bDIFF=($aBLUE-$_aBLUE)
for i in `seq 1 $NUM_STEPS`
do
let Rval=$(echo "$_aRED $rDIFF $i $NUM_STEPS" | awk '{printf "%.0f \n", $1+($2*($3/$4))}')
let Gval=$(echo "$_aGREEN $gDIFF $i $NUM_STEPS" | awk '{printf "%.0f \n", $1+($2*($3/$4))}')
let Bval=$(echo "$_aBLUE $bDIFF $i $NUM_STEPS" | awk '{printf "%.0f \n", $1+($2*($3/$4))}')
[ $DEBUG -eq 1 ] && echo " i Rval Gval Bval = "$i $Rval $Gval $Bval
xfconf-query -c xfce4-panel -p /panels/panel-$PANEL/background-color -s $Rval -s $Gval -s $Bval -s 0
sleep 0.05
done
exit 0