I think the most flexible way is that you yourself must take control of the main window instead of the storyboard.
When the application finishes launching, you can show the main window or not according to the application policy, as shown 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) }
Actually, the toggleDock method changes the way the application is displayed.
// 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 info.plist only allows your Cocoa application to hide the user interface.
Chen
source share