1

I'm writing a small program on macOS as a menubar program which can detect other app's window information such as window position, whether it has a default button, etc.

I can add observer to monitor when other app did activicated and get a NSRunningApplication object. But the information in NSRunningApplication is limited, only include bundle name, url, icon, hidden or not information.

@objc func onAppFocusChange(_ notification: NSNotification){
        guard let userInfo = notification.userInfo!["NSWorkspaceApplicationKey"] as? NSRunningApplication else {return}

        guard let appName = userInfo.localizedName else {return}
        print("\(appName)")
}


func addNotifications(){

    NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(onAppFocusChange(_:)), name: NSWorkspace.didActivateApplicationNotification, object: nil)
}

So as my question title, how can I get other app's current window information, such as position, subview's hierarchy etc.

codingchef
  • 21
  • 5
  • Possible duplicate of [how to traverse window/view hierarchy of other application in OS X?](https://stackoverflow.com/questions/33472289/how-to-traverse-window-view-hierarchy-of-other-application-in-os-x) – Willeke May 23 '19 at 12:15

0 Answers0