Getting the main application window using an NSRunningApplication instance

I am seeing an NSWorkspaceDidDeactivateApplicationNotification notification to get an application that has just lost focus. I get an instance of NSRunningApplication that you get from the userInfo dictionary key - NSWorkspaceApplicationKey - the notification object.

I thought I could get the main window from the application from the notification, but I'm not sure where to go from here, since NSRunningApplication seems rather limited. Any help would be appreciated.

BTW - I use MacRuby, but the answer does not have to be in MacRuby.

thanks

+6
objective-c macruby macos
source share
3 answers

Apple has traditionally been quite locked up in this matter. NSRunningApplication itself was introduced in 10.6, and as you said, it is a bit limited. Depending on what you want to do, the answer may be in the “Accessibility Framework” or it may be the CGWindow API . You can use the processIdentifier from NSRunningApplication to match these APIs.

+4
source share

It is very difficult to get the main window of other applications; they are not even guaranteed by Cocoa! They can be either Carbon, or Java, or Qt, or Mono ... Thus, you cannot get another application NSWindow, unless you hack it. You can try the accessibility API to get window information, etc. Other applications regardless of the structure used, but it is not so simple.

+2
source share

If an application does not participate in IAC through AppleScript or any other means, you simply do not touch its windows or anything else outside of its own heap space.

+1
source share

All Articles