Change to other space (MacOSX) programmatically

Finally I found a solution. I can't change to a certain space programmatically but I can make my window behave like other non NSBorderlessWindowMask if [window setMovableByWindowBackground:YES] is done. That was the final purpose of this question :)

The solution is written (with some detail) here because that question seems to be older (or maybe a duplicate of this question?)

Is there a way to make a custom NSWindow work with Spaces


Unfortunately there's no public API which allows you to do this, but if you're willing to use the Private API it's possible. Take a look at CGSPrivate.h and you'll see you can make a call like this:

CGSConnection connection = _CGSDefaultConnection();
CGSMoveWorkspaceWindowList(connection, &windowNumber, 1, newSpaceNumber);   

Note that using this private API will cause your app to be rejected from Apple's Mac App Store though.