This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Bash script for split image wallpaper in multiple monitor

Tags: None
(comma "," separated)
masierorick
Registered Member
Posts
1
Karma
0
Goodmorning everyone
I think I would like to attach a script written in bash to this post useful for the automatic division of the image in case you have multiple monitors in kde.
It manages the distribution of the image, generating single images to be applied to the monitors you own.
Greetings

Code: Select all
#!/bin/bash
#Splitting wallpaper program - Kde desktop
#Program developed from masierorick - 19/12/2019
#email : masierorick@gmail.com
#Public GPL licence
# Necessita di kde-baseaps-bin e xdotool installato

CURRENT_USER="$USER"

export DISPLAY=:0
export XAUTHORITY=/home/${CURRENT_USER}/.Xauthority
export HOME=/home/${CURRENT_USER}/

 #determina il numero di monitor presenti
 MONITOR=$(xrandr | grep -w connected | wc -l)   

 #Verifica se pacchetti kde-baseapps-bin e xdotool installati
pacchetto= dpkg-query -s kde-baseapps-bin | grep Status | awk '{ print $4 }' > /dev/null ;
if [ "$pacchetto" = "not-installed" ] ;
  then
    sudo apt-get install kde-baseapps-bin -y ;
  fi
 
pacchetto= dpkg-query -s xdotool | grep Status | awk '{ print $4 }' > /dev/null ;
if [ "$pacchetto" = "not-installed" ] ;
  then
    sudo apt-get install xdotool -y;
  fi
 
if [ $MONITOR -gt 1 ]; then   
 FILESTRING=$(/usr/bin/kdialog --getopenfilename "/$HOME" "*.jpg|*.gif" --title="Open image to split")

 if [ ! -z "${FILESTRING}" ]; then
 
   filename=${FILESTRING##*/}
   basename=${filename%\.*}
   CURRENT_DIR=${FILESTRING:0:$((${#FILESTRING}-${#filename}))}
 
  DESTFILE="$CURRENT_DIR$basename""_%d.jpg"
 
  case "$MONITOR" in
   2) PERC="50%"
   ;;
   3) PERC="34%"
   ;;
   4) PERC="25%"
   ;;
   
  esac
 
  RESOL="$PERC""x100%"
  convert -crop $RESOL +repage "$FILESTRING" "$DESTFILE"
 
  #codice per installare un wallpaper
  EN_CONSOLE1="Desktop Shell Scripting Console"
  EN_CONSOLE2="Plasma Desktop Shell"
  LOCALE=`echo $LANG | sed 's/\..*$//'`
   #restituisce it_IT
   #echo $LOCALE
  if [[ $LOCALE != "" ]]; then
        JS_CONSOLE1=`LANGUAGE=$LOCALE gettext -d plasma-desktop -s "$EN_CONSOLE1"`
     JS_CONSOLE2=`LANGUAGE=$LOCALE gettext -d plasma-desktop -s "$EN_CONSOLE2"`
     JS_CONSOLE="$JS_CONSOLE1 – $JS_CONSOLE2"
  else
         JS_CONSOLE="$EN_CONSOLE1 – $EN_CONSOLE2"
   fi
  #echo $JS_CONSOLE
 
  for ((i=0;i<$MONITOR;i++)) ; do
 
   
   js=$(mktemp).js
   cat > $js <<_EOF
   var activity = desktopForScreen($i);
   var wallpaper = "$CURRENT_DIR$basename" & "_$i".jpg;
   activity.wallpaperMode='SingleImage';
   activity.currentConfigGroup =  Array("Wallpaper", "image");
   activity.writeConfig("wallpaper", wallpaper);
   activity.reloadConfig();
   
_EOF
       
   qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.loadScriptInInteractiveConsole "$js" > /dev/null
   rm -f "$js"
  done
 fi
else
  MESSAGE=$(/usr/bin/kdialog --sorry "Your screen own only one monitor!")

fi
     



Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]