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.