API来获取其他应用程序的窗口/文档名称 [英] API to grab other application's window/document name

查看:324
本文介绍了API来获取其他应用程序的窗口/文档名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在可可中有一个API,您可以在其中获取应用程序的窗口/文档名称?我已经有 [[NSWorkspace sharedWorkspace] launchedApplication] 来获取所有可用的应用程序,所以我可以访问包名称或进程ID。

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.

推荐答案

你假设应用程序有一个只有一个窗口。这不是真的;一个应用程序可以有很多窗口。

You're assuming that the application has only one window. This is not true; an application can have many windows.

对于自己的应用程序,使用 [NSApp windows] 他们。具体来说,对于文档窗口,

For your own app, use [NSApp windows] to get an array of them. For document windows specifically, ask the document controller.

对于其他应用程式,请使用辅助功能或CGWindowList查看其窗口。没有简单的方法只要求文档窗口,因为并不是所有的应用程序都是基于文档的,并且并非所有基于文档的应用程序都基于NSDocument。

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.

这篇关于API来获取其他应用程序的窗口/文档名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆