Skip to content

Instantly share code, notes, and snippets.

@h3ct0rjs
Last active February 5, 2017 15:44
Show Gist options
  • Save h3ct0rjs/81c0381b8d880ca7949688f42a211631 to your computer and use it in GitHub Desktop.
Save h3ct0rjs/81c0381b8d880ca7949688f42a211631 to your computer and use it in GitHub Desktop.
Adaptation from Anachron's original block to my computer laptop acer aspire one.
#!/bin/bash
xrandrOut=$(xrandr)
vgaName=$(echo "${xrandrOut}" | grep -i 'VGA' | awk '{print $1}')
lvdsName=$(echo "${xrandrOut}" | grep -i 'LVDS' |2 awk '{print $1}')
activeDisplays=$(echo "${xrandrOut}" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/" | tr -s '\n' ' ')
displayFile='/tmp/.displays'
if [[ -f "${displayFile}" ]]; then
oldDisplays=$(cat "${displayFile}")
else
oldDisplays=""
fi
if [[ "${oldDisplays}" != "${activeDisplays}" ]]; then
change="yes"
else
change="no"
fi
# External, HDMI + VGA
if [[ "$activeDisplays" =~ "${vgaName}" ]]; then
if [[ "${change}" = "yes" ]]; then
$(xrandr --output "${lvdsName}" --primary --auto)
$(xrandr --output "${vgaName}" --auto --left-of "${lvdsName}")
$(feh --randomize --bg-fill /home/user/.wallpapaers/*) #set different wallpapers to vga and lvds1.
#checking if is there any option to enable just one wallpaper to both displays.
fi
echo "VGA"
echo "VGA"
echo ""
# Only one internal
elif [[ "$activeDisplays" =~ "${lvsdName}" ]]; then
if [[ "${change}" = "yes" ]]; then
$(xrandr --output "${lvdsName}" --primary --auto)
$(xrandr --output "${vgaName}" --off)
fi
echo "LVDS"
echo "LVDS"
echo ""
fi
if [[ "${change}" = "yes" ]]; then
echo "${activeDisplays}" > "${displayFile}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment