Preview:
##sudo nano /etc/udev/rules.d/95-monitor-hotplug.rules

SUBSYSTEM=="drm", RUN+="/usr/local/bin/fix_tv_state.sh"

##---------------------



##sudo nano /usr/local/bin/fix_tv_state.sh

#!/bin/sh
#Fix TV state when HDMI link is lost.

export XAUTHORITY=/home/marco/.Xauthority

OUTPUT="HDMI1"
BAD_MODE="1280x720"
GOOD_MODE="1920x1080"

for MODE in $BAD_MODE $GOOD_MODE; do
 sleep 2
 DISPLAY=:0 xrandr --output $OUTPUT --mode $MODE
 sleep 2
done

##--------------------

sudo chmod +x /usr/local/bin/fix_tv_state.sh
sudo udevadm control --reload-rules

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter