Automated way to move Desktop to Different Monitor?

I have a somewhat extreme setup on my main Mac - 6 monitors. This helps considerably with my workflow, where I review lots of documents and do research on websites and thus refer to multiple documents and websites simultaneously.

It is easy using Mission Control to move a Desktop from one monitor to another by dragging it over to another monitor. However it would b even nicer to be able to do this programmatically.

Is there any way using Applescript or Keyboard Maestro or BTT etc to be able say to “Move Desktop 16 to Main Monitor.” I see that BTT lets me choose any Desktop as the primary focus; that is a start, but it does not let me move that Desktop programmatically to a different monitor. Can that be done?

Following for content

FYI you don’t need to post that you’re following - just set it to Watching in the thread.

Thanks for the tip…

Noticed you joined two years ago, and are being civil. :+1:

@rkaplan: As far as I have been able to determine thus far, moving a Desktop is not possible on a programmatic basis. The only interface that I have ever seen for doing so is via Mission Control at the UI level.

I am sure you are aware that windows can be moved between monitors relatively easily with tools like Keyboard Maestro - although there is a catch here, because as far as I have so far figured out, KM does not let you easily specify which monitor you are going to move to. In other words, I have not been able to figure out in KM how to easily convert the numerical order by which it addresses monitors into the specific monitor correlated with that number in order. (I should say that it is doable IF the monitors are of different screen resolutions by getting the dimensions of each monitor and correlating it with the numerical index in KM, but if the monitors are all the same resolution then it is a more difficult task, one that I have not spent time trying to sort out.)

It may be possible to move an entire Desktop using AppleScript with UI scripting (eg ‘tell application “System Events” to …’) but I have yet hack out something that actually works.

I believe, but am not certain, that Desktops are maintained by the WindowServer process, and as such as also not constructs at the level of the system window handling, eg I do not know that you could implement a solution in Objective C or Swift either.

I’d be interested in any solutions that anyone else can suggest and any corrections to my understanding above.

In googling around a bit, I stumbled on a project called “yabai” at which is a tiling window manager for MacOS. It may be that this program has the ability to control Desktops, but I am not sure from the description and haven’t done more than a cursory glance through the underlying code. Based on updates to the git repository I am guessing it is still being developed/maintained, but YMMV on using this, especially as it requires SIP to be (temporarily) disabled to install a Dock extension. I am cautious about relying on such tools for production work; whether they survive across OS updates is always worrisome to me.