tags:

views:

469

answers:

1

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.

+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
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
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
(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
Thanks for the heads up, I do hope Adobe Suites plays well, otherwise its going to be a headache.. :/ Thanks though
John
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
Yup. Not just CS4—many applications have at least one Inspector, and they don't always call it simply “Inspector”.
Peter Hosey