title: Get NSScreen with the keyboard focus on sandbox
body: <p>What I want to know is which <code>NSScreen</code> has keyboard focus. </p>
  
  <p>First I added an observer for <code>NSWorkspace.didActiveApplicationNotification</code> and whenever <code>foo</code> method is called I need to determine which <code>NSScreen</code> has keyboard focus.</p>
  
  <pre><code>NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(foo), name: NSWorkspace.didActivateApplicationNotification, object: nil)
  </code></pre>
  
  <p>All I have from this notification is <code>NSRunningApplication</code> object, but it doesn't tell me which screen is focused.</p>
  
  <p>In <a href="https://developer.apple.com/documentation/appkit/nsscreen" rel="nofollow noreferrer">NSScreen documentation</a> I found <a href="https://developer.apple.com/documentation/appkit/nsscreen/1388371-main" rel="nofollow noreferrer">main property</a> of NSScreen with description </p>
  
  <blockquote>
    <p>Returns the screen object containing the window with the keyboard
    focus.</p>
  </blockquote>
  
  <p>It's exactly what I want, but it doesn't work as I thought. It returns the wrong screen. In the header file, I found this information</p>
  
  <blockquote>
    <p>// cached value, possibly stale</p>
  </blockquote>
  
  <p>I tried Accessibility, everything was OK, but it doesn't work when Sandbox is enabled so I can't use it.</p>
  
  <p>Does anybody have any idea how to get NSScreen object with keyboard focus?</p>