Getting the main window of an app via an NSRunningApplication instance

后端 未结 3 1504
醉梦人生
醉梦人生 2020-12-11 05:54

I\'m observing NSWorkspaceDidDeactivateApplicationNotification notification to get the application that has just lost focus. I\'m ending up with an instance of NSRunningAppl

相关标签:
3条回答
  • 2020-12-11 05:59

    It's very difficult to get the main window of other apps; they're not even guaranteed to be Cocoa! They can be either Carbon or Java, or Qt, or Mono... So there's no way you can get NSWindow of another app, unless you do a hack. You can try Accessibility API to get the window info etc. of other apps independently of the framework used, but it's not so easy to use.

    0 讨论(0)
  • 2020-12-11 06:16

    Unless the application opts to participate in IAC via AppleScript support or some other means, you simply don't touch its windows or anything else outside of your own heap space.

    0 讨论(0)
  • 2020-12-11 06:22

    Apple has traditionally been pretty locked-down about this sort of thing. NSRunningApplication itself was just introduced in 10.6, and as you said, it's a bit limited. Depending on what you want to do, the answer might be in the Accessibility framework or it might be the CGWindow API. You can use the processIdentifier from the NSRunningApplication to match it up with those APIs.

    0 讨论(0)
提交回复
热议问题