Open an application in a space using applescripts

3.9k Views Asked by At

I am trying to create a script that will open an application in a specific "space". So let's say I am on space 1 working in the terminal and then I want to be able to open safari in space 4. Is there a way to do this?

I have done some searching and found only ways to set the system profile options. Maybe I should tell you my end goal in case what I am attempting is not possible.

I use a laptop and plugin in to multiple stations, home, office, and travel. I want to create different window layouts for each one. So I will need an apple script telling it to open applications in varios spaces and different dimensions. I hope this makes sense. Ask me for clarification if it doesn't thanks!

PS the answer doesn't necessarily have to be any applescript I just thought that would be the easiest way :)

3

There are 3 best solutions below

4
On BEST ANSWER

It is possible to do some scripting of application Space preferences by using the scripting interface to the System Events.app. See the answer to a similar question here.

0
On

Here's a list of applescript commands for Spaces. There's a couple things there that might help you.

0
On

The easiest way I've found is via GUI scripting. Make sure the Spaces menu is active on the upper right of your computer. That lists the spaces by number. You can then just write a GUI script to select the menu item of the space you wish. That will switch to that space. Then do an activate Applescript to open the application there.

Let me know if you need sample code demonstrating this. I have some in Python + Appsscript that does this but I should be easily able to convert it back to Applescript proper if you need it.