Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving a Window to a New Space in Mission Control

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.

like image 305
LandonSchropp Avatar asked Aug 13 '11 08:08

LandonSchropp


1 Answers

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.

like image 62
Gavin Brock Avatar answered Oct 13 '22 20:10

Gavin Brock