I have a statusbar application, which runs in the menu bar. Therefore I set Application is agent (UIElement) to true in the info.plst.
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