7" official touchscreen - auto switch to HDMI

Hi there!

lately i bought rPi2 with official 7" touch screen. Everything works fine but to use HDMI i need to edit /boot/config.txt, put there display_default_lcd=0 and then reboot.

Reboot is not an issue but I wonder is there any option to change output automatically? If HDMI cable is connected output should go to HDMI if not to LCD.

I’m familiar a little bit with bash/python so my question is there a way to write some script which recognize on boot HDMI status and then shitch output accordingly?

Where I should look for?

Thanks in advance!
MT