-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-display
executable file
·61 lines (52 loc) · 1.22 KB
/
toggle-display
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# toggle-display.sh
#
# Iterates through connected monitors in xrander and switched to the next one
# each time it is run.
#
# get info from xrandr
xStatus=`xrandr`
connectedOutputs=$(echo "$xStatus" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutput=$(echo "$xStatus" | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
connected=$(echo $connectedOutputs | wc -w)
# initialize variables
execute="xrandr "
default="xrandr "
i=1
switch=0
for display in $connectedOutputs
do
# build default configuration
if [ $i -eq 1 ]
then
default=$default"--output $display --auto "
else
default=$default"--output $display --off "
fi
# build "switching" configuration
if [ $switch -eq 1 ]
then
execute=$execute"--output $display --auto "
switch=0
else
execute=$execute"--output $display --off "
fi
# check whether the next output should be switched on
if [ $display = $activeOutput ]
then
switch=1
fi
i=$(( $i + 1 ))
done
# check if the default setup needs to be executed then run it
echo "Resulting Configuration:"
if [ -z "$(echo $execute | grep "auto")" ]
then
echo "Command: $default"
`$default`
else
echo "Command: $execute"
`$execute`
fi
echo -e "\n$(xrandr)"