About box with Application is agent (UIElement) set to YES?

Started a new application a few days ago and i figured it out.

[NSApp activateIgnoringOtherApps:YES]

Does the trick!


I think the most flexible way is that you should take your main window control by yourself instead of the storyboard.

When Application did finish launching, you can show main window or not according to your application policy as below:

 switch AppDefaults.shared.applicationRunMode {
        case .menuAndDock:
            _ = ApplicationMode.toggleDock(show: true)
            MainWindowController.shared.window?.makeKeyAndOrderFront(nil)
        case .menuOnly:
            _ = ApplicationMode.toggleDock(show: false)
            _ = MainWindowController.shared.window
        default:
            MainWindowController.shared.window?.makeKeyAndOrderFront(nil)
        }

What the toggleDock method actually does is to change the way your application show.

// Get transform state.
let transformState = show ?
            ProcessApplicationTransformState(kProcessTransformToForegroundApplication)
            : ProcessApplicationTransformState(kProcessTransformToUIElementApplication)

// Show / hide dock icon.
var psn = ProcessSerialNumber(highLongOfPSN: 0, lowLongOfPSN: UInt32(kCurrentProcess))

let transformStatus: OSStatus = TransformProcessType(&psn, transformState)
return transformStatus == 0

UIElement in the info.plist only enable your Cocoa Application the ability to hide UI.