Get a list of opened windows cocoa

前端 未结 4 1535
北海茫月
北海茫月 2021-01-05 12:31

I\'m 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, since this would be an easy task. I want to list wind

相关标签:
4条回答
  • 2021-01-05 13:10

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

    It's a Carbon function, though - not Cocoa - but perfectly callable from a Cocoa app and documented here: Quartz Window Services Reference : CGWindowListCopyWindowInfo().

    0 讨论(0)
  • 2021-01-05 13:10

    I have Preview running with 10 pdf opened, my program should be able to retrieve a list with all those pdf.

    Well, that's the hard part. You can get the windows via Accessibility, but Accessibility doesn't associate them with any kind of document object.

    AppleScript would work for some applications, but Preview isn't one of them. Indeed, most apps aren't.

    So, you can get a list of windows easily enough, but getting meaningful information about or from inside those windows ranges from tricky to impossible. Your best bet may be a combination of Accessibility, AppleScript, and bug reports for un-scriptable applications, and the knowledge that your app will not work on everything.

    0 讨论(0)
  • 2021-01-05 13:17

    First, Cocoa is not an acronym, so it's not "COCOA". :-)

    Second, your only (public API) option is the Accessibility API. You'll have to enable access for assistive devices in the Accessibility panel in Systems Preferences.

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

    0 讨论(0)
  • 2021-01-05 13:21

    if you need WIndow List or UI Specific of window control, if its UI Specific control ,you can refer Apple son of Grab example,
    It displays Windows List running on the desktop, probably you can trim down as par your needs.

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