Advertisement
AmourSpirit

Swap Displays in Ubuntu Linux

Nov 16th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. # get info from xrandr
  2. connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
  3. activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
  4.  
  5. # initialize variables
  6. execute="xrandr "
  7. default="xrandr "
  8. i=1
  9. switch=0
  10.  
  11. for display in $connectedOutputs
  12. do
  13.     # build default configuration
  14.     if [ $i -eq 1 ]
  15.     then
  16.         default=$default"--output $display --auto "
  17.     else
  18.         default=$default"--output $display --off "
  19.     fi
  20.  
  21.     # build "switching" configuration
  22.     if [ $switch -eq 1 ]
  23.     then
  24.         execute=$execute"--output $display --auto "
  25.         switch=0
  26.     else
  27.         execute=$execute"--output $display --off "
  28.     fi
  29.  
  30.     # check whether the next output should be switched on
  31.     if [ $display = $activeOutput ]
  32.     then
  33.         switch=1
  34.     fi
  35.  
  36.     i=$(( $i + 1 ))
  37. done
  38.  
  39. # check if the default setup needs to be executed then run it
  40. echo "Resulting Configuration:"
  41. if [ -z "$(echo $execute | grep "auto")" ]
  42. then
  43.     echo "Command: $default"
  44.     `$default`
  45. else
  46.     echo "Command: $execute"
  47.     `$execute`
  48. fi
  49. echo -e "\n$(xrandr)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement