Welcome!
Important information
-- Spectre and Meltdown vulnerabilities
-- Change in MX sources

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-17.1 Final release info here
-- antiX-17 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

Wallpaper Changer / Panel Color Fader

Here you can exchange scripts that you created or have permission to share with other users.
Post Reply
Message
Author
User avatar
Jerry3904
Forum Veteran
Forum Veteran
Posts: 22419
Joined: Wed Jul 19, 2006 6:13 am

Wallpaper Changer / Panel Color Fader

#1 Post by Jerry3904 » Tue May 12, 2015 4:46 pm

ToZ over on the Xfce Forum has created a script that does the following:

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
Might be worth giving it a try on a lazy afternoon.
Production: 4.15.0-1-amd64, MX-17.1, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 8 GB, Kingston SSD 120 GB and WesternDigital 1TB
Testing: AAO 722: 4.15.0-1-386. MX-17.1, AMD C-60 APU, 4 GB

User avatar
asqwerth
Forum Veteran
Forum Veteran
Posts: 3254
Joined: Sun May 27, 2007 5:37 am

Re: Wallpaper Changer / Panel Color Fader

#2 Post by asqwerth » Sat May 16, 2015 1:48 am

I don't write scripts and this isn't tested on XFCE but here's a shorter wallpaper changing script without any background colour matching.

The foundation of this came from the Tips and Tricks sub-board of the Semplice Linux forum. Semplice is an openbox Sid distro. So the original command to change the wallpaper used nitrogen, since that's the program often used in openbox to manage the background.

I adapted it for use in Kanotix LXDE (Debian Jessie) so instead of nitrogen, I'm using pcmanfm to change the wallpaper.

I'm assuming that when you use it for XFCE you just need to change the pcmanfm command bit 4th line from the bottom (ie. pcmanfm --wallpaper-mode=stretch -w) to

Code: Select all

xfconf-query -c xfce4-desktop -p $xfIMAGE -s
See: http://askubuntu.com/questions/380550/x ... mmand-line


Save the script below in ~/.local/share/applications/changer.sh and make it executable. Since that's a home sub-folder, you can change it easily any time without root.

Add an autostart entry for this script from the XFCE Control Centre >> Sessions and Startup. For Kanotix I couldn't just add a .desktop file for the script in ~/.config/autostart because it clashed with the starting of Compiz (part of Kanotix's default install) and failed to start. Since I love having Compiz, I amended the /usr/bin/startlxde file instead so that the startup order could be sorted out.

I group my wallpaper into different folders and the number of folders is still being added to. I open the script file to change the active folder and to add any new folders.

I haven't tried it in XFCE because that has its native background changer.


Code: Select all

#!/bin/bash
sleep 5
# configuration variables

# the directory with your wallpapers, either .jpg or png; just list all your wallpaper folders and uncomment the one you want to use
# DIR="/media/sdc1/Wallpapers/foldername1"
# DIR="/media/sdc1/Wallpapers/foldername2"
DIR="/media/sdc1/Wallpapers/foldername3"

# xfconf image location - I think you need this for XFCE  
# see here for more details on the image location path to use: http://askubuntu.com/questions/380550/xubuntu-how-to-set-the-wallpaper-using-the-command-line 
xfIMAGE="/backdrop/screen0/monitor0/image-path"

# command for openbox:   nitrogen --set-zoom-fill "${wallpapers[$((RANDOM%${#wallpapers[@]}))]}"

# length of each cycle - to set time interval between changes
LEN='8m'

shopt -s nullglob
wallpapers=($DIR/*.{jpg,jpeg,png,JPG.JPEG,PNG})
while [[ ${wallpapers[0]} ]]
do
#  pcmanfm --wallpaper-mode=stretch -w "${wallpapers[$((RANDOM%${#wallpapers[@]}))]}"  -- this is where it's different for XFCE

  xfconf-query -c xfce4-desktop -p $xfIMAGE -s "${wallpapers[$((RANDOM%${#wallpapers[@]}))]}"
  sleep "$LEN"
done

exit 0
Desktop: Intel i5-4460, 16GB RAM, Intel integrated graphics
Clevo N130WU-based Ultrabook: Intel i7-8550U (Kaby Lake R), 16GB RAM, Intel integrated graphics (UEFI)
ASUS X42D laptop: AMD Phenom II, 6GB RAM, Mobility Radeon HD 5400

Post Reply

Return to “Scripts”