2

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 :)

gdoubleod
  • 1,268
  • 3
  • 19
  • 33

3 Answers3

2

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

regulus6633
  • 18,848
  • 5
  • 41
  • 49
0

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.

Community
  • 1
  • 1
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • Although Spaces is a useful feature, it is limited in its functionality. You wouldn't have to remove all the preferences; just create the appropriate AppleScript(s) and run them when you want to switch configurations. You can run AppleScripts from the command line or a shell script with `osascript` (see `man osascript`). It's easy enough to experiment with. – Ned Deily Apr 17 '11 at 22:36
  • a quick question for you how can I clear the preferences I have already set in my spaces preferences? I tried this but it didn't work. `my remove_all_spaces_application_bindings()` `on remove_all_spaces_application_bindings() tell application "System Events" to tell spaces preferences of expose preferences to set application bindings to {} end remove_all_spaces_application_bindings` sorry for the bad formatting.. – gdoubleod May 02 '11 at 07:08
  • @gdoubleod, some tips on using StackOverflow: when you ask a question, you should either mark an answer as accepted (so that the answerer receives reputation points) or refine your original question by editing it until you get an answer that you can accept. And people won't be interested in answering new questions in comments, especially if they can't be easily read. There's a reason why the formatting options in comments are limited! – Ned Deily May 02 '11 at 09:39
  • sorry about the multiple edits I was trying to get the formatting better... I actually kind of figured out the answer to my follow up... well at least a work around... but I'll post up my question thanks! :) – gdoubleod May 03 '11 at 06:06
0

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.

Clark
  • 833
  • 4
  • 6