Get a list of cocoa open windows

I am new to Cocoa and I want to know how I can get a list of all open windows. I'm not talking about running programs, as that would be an easy task. I want a list of windows, for example, if I have a Pre-launch with open 10 pdf, my program should be able to get a list with all of these pdfs. I also want to know if any API is available for interacting with windows that are already open (and possibly move them or do something else) from an external application. Thanks.

+4
source share
4 answers

First, Cocoa is not an abbreviation, therefore not "COCOA". :-)

Secondly, your only (open API) is the Accessibility API. You must enable access for assistive devices in the Availability panel in System Preferences.

Take a look at the docs to get started: Accessibilty Overview

+5
source

I have Preview running with open 10 pdf, my program should be able to retrieve a list with all these pdfs.

Well, thatโ€™s the hard part. You can get windows through Accessibility, but Accessibility does not associate them with any document object.

AppleScript will work for some applications, but Preview is not one of them. Indeed, most applications are not.

Thus, you can get a list of windows quite easily, but getting meaningful information about or from inside these windows varies from difficult to impossible. Your best bet may be a combination of Accessibility reports, AppleScript, and errors for scriptless applications, as well as the knowledge that your application will not work at all.

+3
source

You can use CGWindowListCopyWindowInfo to get a list of windows in the current user session.

This is a Carbon function, but - not Cocoa - but completely invoked from a Cocoa application and documented here: Quartz Window Services Reference: CGWindowListCopyWindowInfo () .

+3
source

if you need a WIndow list or a window-specific user interface, if its a specific user interface control, you can send Apple a son of Grab example,
It displays a list of Windows that runs on the desktop, perhaps you can crop it to suit your needs.

0
source

Source: https://habr.com/ru/post/1299351/


All Articles