applescript – Is there a way to programatically detect Universal Control monitors and arrange displays?

0
21

[ad_1]

I’ve been trying to find a way to programatically detect and script Universal Control.

(Some background: imagine you have two Macs—call them A and B—both hooked up to external displays over USB-C to DisplayPort/HDMI adapters—let’s call them X and Y. Most of the time, A is connected to X and B is connected to Y, as X is a bigger monitor on the left and Y is a smaller monitor on the right. But occasionally, one will want to switch these so B is connected to X and A is connected to Y. In this situation, it’d be good if X is always to the left of Y, but to do this, one must manually rearrange the monitors in System Settings.)

I’ve tried displayplacer, calling Application("Image Events").displays() (in JavaScript-flavoured osascript), and hs.screen functions in Hammerspoon. I’ve also delved through a whole bunch of Apple Developer Documentation, and tried calling some of the CoreGraphics Display-related functions (specifically the ones to get displays) described in Quartz Display Services (through a Rust wrapper), but I’m reasonably sure Universal Control monitors are not treated as monitors by macOS and after a pretty diligent search, I can’t find any reference to any way to get the status of Universal Control or programatically rearrange UC virtual displays.

If there isn’t any way to script Universal Control using either AppleScript, underlying system libraries (etc.), the only real alternative looks like doing some really nasty UI automation, which is probably likely to be so fragile and unpleasant as to make it not worth bothering with.

[ad_2]