Switching monitor inputs programmatically, on M1 MBP

I’ve got a monitor that has multiple inputs: one is DisplayPort from my M1 MacBook, and VGA from my TrueNAS server.
For a while I was just switching the input using the buttons on the monitor, but who wants to keep reaching up and to the right for that?!

Here’s how I was able to map Cmd+F6 and Cmd+F7 to switch between two arbitrary inputs on my monitor.

  1. Install m1ddc using Homebrew: brew install m1ddc
    m1ddc is a command-line tool for controlling the display on an M1 Mac. I’m not sure what the equivalent is for Intel Macs.

  2. List your displays: m1ddc display list
    This should produce a list of displays. Like this:

    $ m1ddc display list                              
    [1] DELL U2720QM (BB7A124B-B761-4DE2-B597-7E1A432EAAA2)
    [2] (null) (37D8832A-2D66-02CA-B9F7-8F30A301B230)
    [3] DELL U2410 (320C4B79-F89E-4601-8592-DA40A547289B)
  3. Change the input on the display you want to control: m1ddc display 320C4B79-F89E-4601-8592-DA40A547289B set input 15
    This should switch the input on the monitor to whatever you specified. In my case, 15 is DisplayPort.
    The docs specify the following inputs: DisplayPort 1: 15, DisplayPort 2: 16, HDMI 1: 17, HDMI 2: 18, USB-C: 27.
    It’s possible to use 1/2 for picking a display, but the indexes change when your displays change, for instance if you close the lid on your laptop. So it’s better to use the display UUID instead.

  4. Experiment with setting the input on whatever display you want.
    I experimented a bit and found that 1 was VGA and 15 was DisplayPort on my monitor.

  5. Using BetterTouchTool, I mapped Cmd+F6 to m1ddc display 320C4B79-F89E-4601-8592-DA40A547289B set input 15 and Cmd+F7 to m1ddc display 320C4B79-F89E-4601-8592-DA40A547289B set input 1.
    Now I can switch inputs on my monitor with a simple keyboard shortcut!

m1ddc1 doesn’t seem to work when the monitor turns off due to inactivity.
Not sure why, and not sure if I’ll bother debugging this issue just yet.
The workaround is to not let the monitor turn off due to inactivity.
So either configure the device on the second input to never go into sleep mode, or remember to switch the input before the monitor goes to sleep.

Leave a Reply

Your email address will not be published. Required fields are marked *