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.

Community
  • 1
  • 1
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
  • This seems a bit too power-usery for StackOverflow. Is this for personal use or for actual development? – Jonathan Grynspan Sep 07 '11 at 01:48
  • 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: http://thecocoabots.com/blog/post/377/. – LandonSchropp Sep 07 '11 at 02:34
  • I'm looking for an answer for this too. Did you manage to do it? Can you update? – SimonW Jan 17 '13 at 19:22
  • I had to give up. Sorry. Let me know if you figure it out. – LandonSchropp Jan 18 '13 at 00:00

2 Answers2

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.

Community
  • 1
  • 1
Gavin Brock
  • 5,027
  • 1
  • 30
  • 33
  • 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. – LandonSchropp Sep 21 '11 at 20:27
  • If you need official Frameworks, you are stuck with the [setCollectionBehavior](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWindow/setCollectionBehavior:) call. – Gavin Brock Sep 22 '11 at 05:38
  • Note for Lion: the Space ID you get via `kCGWindowWorkspace` changes between logins. – Mark Jan 08 '12 at 06:51
-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.

garyamorris
  • 2,587
  • 2
  • 17
  • 23
  • 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. – LandonSchropp Sep 12 '11 at 06:31