Search code examples
swiftmacoscocoanswindownsapplication

Open Mac OSX app on current desktop when opened in separate desktop


I'm trying to get a mac app to open on the current desktop when I use a a global keyboard shortcut (that I've overriden manually in the app). However, when I perform the keyboard shortcut, my desktop switches and shows me the app on the desktop it was previously on instead of the current one. The app is active, but on that other desktop.

Currently, I'm calling:

window?.makeKeyAndOrderFront(nil)
NSApplication.shared.activate(ignoringOtherApps: true)

Thanks in advance for the help.


Solution

  • In Interface Builder, select the window in question, and in the Attributes Inspector, change Spaces from Inferred Behavior to Move To Active Space.

    That should allow the window to be shown on the currently active space rather than switching back to whichever space it was shown on last.

    You can also do this programmatically by modifying the window's collectionBehavior:

    window.collectionBehavior.insert(.moveToActiveSpace)