What I want to know is that NSScreen has keyboard focus.
First I added an observer for NSWorkspace.didActiveApplicationNotification and whenever the foo method is called, I need to determine which NSScreen has keyboard focus.
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(foo), name: NSWorkspace.didActivateApplicationNotification, object: nil)
All I received from this notification is the NSRunningApplication object, but it does not tell me which screen is focused.
In the NSScreen Documentation, I found the main NSScreen property with a description
Returns a display object containing a window using the keyboard focus.
This is what I want, but it does not work as I thought. It returns the wrong screen. I found this information in the header file
// cached value, possibly outdated
I tried accessibility, everything was fine, but it does not work when Sandbox is turned on, so I can not use it.
Does anyone know how to get an NSScreen object with keyboard focus?
accessibility cocoa swift macos appstore-sandbox
Raymond
source share