3

Does anyone know how to move an application window to a specific desktop with AppleScripts?

I am asking this because I want to automate the following process, for example:

  1. move the 1st window of Safari to "Desktop 3"
  2. set Mail.app in full-screen mode and place it between "Desktop 3" and "Desktop 4"

Once this kind of process is automated, one can go back to a user-defined "default Desktop allocation", which sounds very useful to me.

Thanks in advance!

(OS: Catalina)

5
  • You can't.­­­­­­
    – CJK
    Mar 13, 2020 at 18:59
  • That’s too bad. Do you know any good alternatives?
    – Yutaro
    Mar 14, 2020 at 5:09
  • As far as I know, Apple don't have a public API that would allow a program to interface with a control Spaces, which is what I think we're talking about. However, if you are referring to the desktop on a different monitor, and it's a physical extension of the active desktop beyond the bounds of your main monitor, then you can move application windows over to that other screen. But, regarding Spaces, I think Apple withdrew access to that for reasons filed under its catch-all "security-over-functionality" initiative. There could be a non-Apple API somewhere but I don't know of any.
    – CJK
    Mar 14, 2020 at 6:55
  • Oh, yes I do… Hammerspoon. I always forget about that, even though it's basically limitless in what one can do / automate with it. And because it doesn't use Apple APIs, it's not particularly limited by the constraints imposed by Apple on many things.
    – CJK
    Mar 14, 2020 at 7:07
  • Thanks a lot!! Yes, I meant Spaces. I haven’t heard of Hammerspoon. I will look into it.
    – Yutaro
    Mar 14, 2020 at 7:37

1 Answer 1

0

I realize this question is old, but this is actually quite doable.

Because there aren't any real scripting exposures in Mission Control, you'll need to manipulate the cursor and thus will need access to the Objective-C bridge. This requires using the JXA variant of AppleScript, but still allows things to run natively without any plugins.

If you're still interested I've shared the solution on my GitHub repository, stephan-hates-osascript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .