How to bring NSWindow to front and to the current Space? How to bring NSWindow to front and to the current Space? swift swift

How to bring NSWindow to front and to the current Space?


To bring your app to the front:

[NSApp activateIgnoringOtherApps:YES];

Swift:

NSApp.activateIgnoringOtherApps(true)

Swift 3:

NSApp.activate(ignoringOtherApps: true)


Perhaps you want:

  [self.window setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces];

Experiment with the other collection behaviors... I found NSWindowCollectionBehaviorMoveToActiveSpace was a bit buggy in 10.5 but it might be better now.


But how to move the app to the user's current Space?

You don't. Spaces hold windows, not applications. (That's why the collectionBehavior property is on NSWindow, not NSApplication.)