Is there an API in cocoa in which you can grab an application's window/document name? I've already got [[NSWorkspace sharedWorkspace] launchedApplication]
to fetch all available applications, so I've got access to the bundle name or process id. What should I look into so that I can get other application's window/document name.
views:
469answers:
1
+2
A:
You're assuming that the application has only one window. This is not true; an application can have many windows.
For your own app, use [NSApp windows]
to get an array of them. For document windows specifically, ask the document controller.
For other apps, use Accessibility or CGWindowList to look at their windows. There's no simple way to only ask for document windows, since not all apps are document-based and not all document-based apps are based on NSDocument.
Peter Hosey
2009-05-21 13:42:39
Accessibility is what Im looking for, thanks for the link.To be specific, it kind of works for me, I just want to grab the key document/key window name that is NSDocument based app. But im just curious, is there any way to get information on windows in applications that are not NSDocument based?
John
2009-05-21 18:57:24
Accessibility works on all applications. The problem is that it will give you all of each application's windows, since it can't tell document windows from other windows. kAXFocusedWindowAttribute is the key window, but that's not always a document window—it may be an open panel, save panel, print panel, alert panel, or About panel, for example.
Peter Hosey
2009-05-21 20:20:57
(Also, you may want to devote special testing to apps such as those in CS4. I don't use those, but since the CS4 apps are incompatible with Spaces, I have a hunch they may fail at accessibility, too.)
Peter Hosey
2009-05-21 20:23:26
Thanks for the heads up, I do hope Adobe Suites plays well, otherwise its going to be a headache.. :/ Thanks though
John
2009-05-22 05:19:50
It does work for CS4, but the thing is CS4 has TONS of other floating windows and palettes in photoshop, so its pretty difficult to programmatically identify the real document window.
John
2009-05-22 05:51:25
Yup. Not just CS4—many applications have at least one Inspector, and they don't always call it simply “Inspector”.
Peter Hosey
2009-05-22 06:07:26