code.fastix.org

Dateiansicht:

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