macOS menubar application: main menu not being displayed

后端 未结 4 1853
Happy的楠姐
Happy的楠姐 2020-12-14 21:36

I have a statusbar application, which runs in the menu bar. Therefore I set Application is agent (UIElement) to true in the info.plst.

4条回答
  •  星月不相逢
    2020-12-14 21:53

    I tried with apple scripts, which appears working as expected.

    Except, after closing by key strokes and then reopening a new window (short time interval), menu will stay selected.

    if NSApp.activationPolicy() == .accessory {
        NSApp.setActivationPolicy(.regular)
    } else {
        var errorDict: NSDictionary?
        NSAppleScript(source: """
            tell application "Dock" to activate current application
            """)?.executeAndReturnError(&errorDict)
        if errorDict != nil{
            print(errorDict!)
            // error executing apple script
            NSApp.activate(ignoringOtherApps: true)
        }
    }
    
    window?.makeKeyAndOrderFront(self)
    

    GIF demo:

    Video link

提交回复
热议问题