code.fastix.org

Dateiansicht:

Datei:Projekte -> Linux-Monitor-Switch für Laptops -> MonitorBeide.sh
md5:e84b01e141d17df18a2b72cbf92b05e2
sha1:90b73f84f437a0bf9f35df24643f1a9b5bee0220
Download-Link:Download
  1. #!/bin/bash
  2.  
  3. changeMonitors="false";
  4. dontChangeAudio="false";
  5. noPresentationMode="false";
  6.  
  7. while [ -n "$1" ]; do
  8.         [ "-c" = "$1" -o "--changeMonitors"  = "$1"    ] && changeMonitors="true";
  9.         [ "-n" = "$1" -o "--dontChangeAudio" = "$1"    ] && dontChangeAudio="true";
  10.         [ "-p" = "$1" -o "--noPresentationMode" = "$1" ] && noPresentationMode="true";
  11.         shift;
  12. done
  13.  
  14. Ports=$(xrandr | grep -P "DisplayPort-[0-9]+ connected" | sed -e "s/ .*$//");
  15.  
  16. myArr+=($Ports);
  17.  
  18. if [ -z "${myArr[1]}" ]; then
  19.         echo "Keine zwei Monitore gefunden. Exit" 1>&2;
  20.         exit 2
  21. fi
  22.  
  23.  
  24. if [ $changeMonitors = "true" ]; then
  25.         dp1=${myArr[0]};
  26.         dp2=${myArr[1]};
  27. else
  28.         dp1=${myArr[1]};
  29.         dp2=${myArr[0]};
  30. fi
  31.  
  32. /usr/bin/xrandr \
  33. --output  $dp1  --primary --scale 1.0 --mode 1920x1080 --rate 60 --pos 0x0    --rotate normal \
  34. --output  $dp2            --scale 1.0 --mode 1920x1080 --rate 60 --pos 1920x0 --rotate normal \
  35. --output eDP --off
  36.  
  37. xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor$dp1/workspace0/last-image -s /home/fastix/Bilder/Wallpaper/papagei-gespiegelt.jpg
  38. xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor$dp2/workspace0/last-image -s /home/fastix/Bilder/Wallpaper/Papagei.jpg
  39.  
  40. if [ $dontChangeAudio = "false" ]; then
  41.         hdmi_audio=$(wpctl status | grep 'Audio.*HDMI' | head -n1 | sed -E 's/^[^0-9]*([0-9]{1,3}).*$/\1/');
  42.  
  43.         if [ -n "$hdmi_audio" ]; then
  44.                 wpctl set-default $hdmi_audio
  45.         else
  46.                 echo "Kein HDMI-Output gefunden. Wird also nicht aktiviert." 1>&2;
  47.                 exit 2
  48.         fi
  49.  
  50. fi
  51.  
  52. if [ $noPresentationMode = "false" ]; then
  53.         xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s true
  54. fi
  55.