Moving a Window to a New Space in Mission Control
Asked Answered
B

2

9

I would like to write a small utility that moves a window from one space to another in OS X Lion. I don't care if the utility is written in AppleScript or Objective-C. What I can't seem to figure out is given a window, how can I move it to a different space. I've seen lots of helpful information in this thread, but nothing about how to actually move the window. If anybody has any thoughts or ideas, I'd appreciate hearing them. Thanks.

Bashee answered 13/8, 2011 at 8:19 Comment(4)
This seems a bit too power-usery for StackOverflow. Is this for personal use or for actual development?Turnpike
The plan was to create an application that would help me manipulate spaces more easily in Lion. There are a few things I would have liked to add to spaces, such as easily swapping the locations of two spaces or fullscreen apps. I even developed a front-end with the idea that Apple would provide APIs to accomplish this. I was going to release this application on the App Store. Unfortunately, this doesn't seem to be possible using provided APIs. I gave up after reading this blog post: thecocoabots.com/blog/post/377.Bashee
I'm looking for an answer for this too. Did you manage to do it? Can you update?Cassicassia
I had to give up. Sorry. Let me know if you figure it out.Bashee
F
3

If you are using objective-c calls, then moving between spaces in 10.7 is actually the same as 10.6 except for one issue. Space ID's were index based in 10.6, but based on something else (not quite a GUID) in 10.7.

If you have a window already in the correct space, the solutions in this question will work (I'm using it in csshX). You can get the space ID with CGSGetWindowWorkspace, and then set it on another window using CGSMoveWorkspaceWindowList.

Now if you don't have the space id - e.g. you just want to move the window to the 2nd space - then I'm as stumped as you are. I'm looking for the linkage between the space id and the index number. (Will update this answer if I find it)

Finally, you mention the App Store in the comment above - this will not be suitable since the CGS* calls use undocumented private frameworks which will get you rejected.

Fulgurant answered 21/9, 2011 at 13:49 Comment(3)
It's too bad that Apple doesn't provide a public API to accomplish this. Unfortunately, I have a requirement that this application must be able to be released in the App Store. Still, thanks for the suggestion.Bashee
If you need official Frameworks, you are stuck with the setCollectionBehavior call.Fulgurant
Note for Lion: the Space ID you get via kCGWindowWorkspace changes between logins.Latchstring
S
-1

You will need to use a custom library, which can be found here http://macscripter.net/viewtopic.php?id=23453, however I'm not sure what kind of support it has in lion.

Sarmentose answered 12/9, 2011 at 4:9 Comment(1)
Unfortunately this doesn't look like it'll work for Lion. Since you can't submit an app to the App Store unless it works for the most current OS X, I'm afraid this won't work. Still, thanks.Bashee

© 2022 - 2024 — McMap. All rights reserved.