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

2

9

Im trying to create a application that should only be visible in the status bar, and not have a window until you press the NSStatusItem menu options. So i have one that should open "about"

[[NSApplication sharedApplication] orderFrontStandardAboutPanel:self];

But nothing shows if I have the Application is agent set to YES. If I change it to NO it works, but I get a application window and all the menu options that i don't want to see.

Any ideas?

Kind regards

Randi answered 26/3, 2011 at 8:21 Comment(0)
R
8

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

[NSApp activateIgnoringOtherApps:YES]

Does the trick!

Randi answered 27/2, 2012 at 15:19 Comment(0)
R
3

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 does is change the way your application shows.

func toggleDock(show: Bool) -> Bool {
    // 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 enables your Cocoa Application the ability to hide UI.

Ridenour answered 8/7, 2019 at 4:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.