[英]How can I list all open windows on Mac from a Python script?
I'd like to be able to grab a list of all windows that are open on macOS/OS X from a Python script.我希望能够从 Python 脚本中获取在 macOS/OS X 上打开的所有窗口的列表。 This would be the Mac equivalent on win32's EnumWindows API call.
这将是 win32 的EnumWindows API 调用的 Mac 等效项。
Ideally, I'd like to be able to use this to get a list of the title/caption text of every open window along with position/size information.理想情况下,我希望能够使用它来获取每个打开窗口的标题/标题文本以及位置/大小信息的列表。
Is there an OS or Cocoa API call that will return this info?是否有将返回此信息的操作系统或 Cocoa API 调用?
You can use pyobjc .您可以使用pyobjc 。 This should get the title names for you:
这应该为您获取标题名称:
from AppKit import NSWorkspace
[apps["NSApplicationName"] for apps in NSWorkspace.sharedWorkspace().launchedApplications()]
A little more background: pyobjc
is implemented using Quartz Window Services , which is the program they used to manage application windows on Mac OS.更多背景知识:
pyobjc
是使用Quartz Window Services 实现的,这是他们用来在 Mac OS 上管理应用程序窗口的程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.