programatically disconnect or change monitor settings on mac

Viewed 41

so - I have a bunch of different machines that I switch between using a usb switcher, and have a bunch of things like mouse, keyboard, camera, other monitors etc hanging off the USB - but the computers are all directly plugged into the big main monitor in various different ways.

I've written stuff in swift and c# for the various machines that detects the usb disconnection and turns off the main screen, and that works great, so it automatically flips to whatever new machine I've moved to - but with my mac laptop I've decided I want to keep the laptop screen as like a second machine and keyboard. The problem is - there's a hdmi connection to the big monitor - and I need the mac to stop sending hdmi, because the screen is now owned by someone else - so I suddenly want the mac limited to the laptop.

On windows it would be easy - you just disable the device, then re-enable it when the docking usb comes back - but I don't know how to do the same thing on the mac. Even from the display settings ui, I can't seem to say "don't use this monitor" - I can say "mirror the laptop display" - which may be good enough, but even that I don't know how to do from code.

so the actual question:

  • how do I programatically "remove" and then later "attach" a hdmi monitor and set it as the main display
  • if that's not possible, how do I programatically switch a monitor between mirroring and not mirroring

Ideally in swift, but python is also viable.

At the moment I literally have to pull out the HDMI from the laptop and then plug it in each time... which is not ideal.

0 Answers
Related