Xrandr help for GPU Passthrough VM

Just trying to get a simple script setup.

Two monitors

Monitor one is connected to on board gpu via hdmi

Monitor two is connected to on board gpu via hdmi and then connected to nvidia gpu via display port.

I need the script to run as follows:
Turn off monitor two hdmi connection
Start vm with virsh command
Turn on monitor two connecting via display port setting the display size

After vm is shut off, i need monitor two to switch back over to hdmi port to previous size.

Script code maybe?
xrandr --output HDMI2 --off
virsh start win10
xrandr --output DISP1 --mode 1920x1080

Now here is where I get stuck. The vm is running so the script should still be up and running cause i didn't call it to exit. I need this script to monitor if the vm is still up. Once its not, i need it to enable HDMI2 to its previous resolution. Any ideas?

This guy in his video is doing what i am looking for https://www.youtube.com/watch?v=37D2bRsthfI
I have messaged him but waiting for a response.