I am trying to create an Application on Mac OS X Lion which requires application to be assigned to All Desktops (Spaces). This can be manually done by Right clicking on application's dock icon and Selecting Options > Assign To > All Desktops. But, I need to find a way to do this via Objective C. Is there a way to achieve this programmatically?
Asked
Active
Viewed 4,246 times
1 Answers
18
You can use method setCollectionBehavior:
of NSWindow
with the NSWindowCollectionBehaviorCanJoinAllSpaces
bitwise flag.
It will make the window visible on all spaces.
NSUInteger collectionBehavior;
// Gets the current collection behavior of the window
collectionBehavior = [ myWindow collectionBehavior ];
// Adds the option to make the window visible on all spaces
collectionBehavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
// Sets the new collection behaviour
[ myWindow setCollectionBehavior: collectionBehavior ];
Note
This method was introduced in Mac OS X 10.6.
On Mac OS X 10.5, you'll need to use the canBeVisibleOnAllSpaces:
method of NSWindow
.

Macmade
- 52,708
- 13
- 106
- 123
-
1Thanks for the solution. I just tried this solution and it works like a charm for Mac OS X 10.6. – user1636849 Sep 02 '12 at 17:48
-
1Works with Mavericks' desktops, too, it seems. – scrrr May 27 '14 at 08:45