-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-hdmi
executable file
·34 lines (29 loc) · 915 Bytes
/
toggle-hdmi
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
#!/usr/bin/env sh
connected=($(xrandr -q | grep ' connected' | awk '{print $1}'))
enabled_num=$(xrandr -q | grep '\*' | wc -l)
echo $connected
echo ${connected[@]}
if [[ "${#connected[@]}" -ne 2 ]]; then
echo "Only $connected outputs connected, can't toggle display"
# Force LVDS only
xrandr --output LVDS1 --auto --output HDMI1 --off
exit 1
fi
# Is HDMI connected?
hdmi_mode="off"
for output in "${connected[@]}"; do
if [[ "$output" == HDMI1 ]]; then
hdmi_mode="on"
fi
done
if [[ $hdmi_mode == "off" ]]; then
echo "HDMI not connected, maybe you mean VGA?"
exit 1
fi
if [[ "$enabled_num" == "1" ]]; then
echo "Enabling HDMI output to the right of laptop"
xrandr --output LVDS1 --auto --pos 0x0 --output HDMI1 --auto --right-of LVDS1
elif [[ "$enabled_num" == "2" ]]; then
echo "Disabling HDMI output"
xrandr --output LVDS1 --auto --output HDMI1 --off
fi