简体   繁体   English

如何从 Python 脚本列出 Mac 上所有打开的窗口?

[英]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.

相关问题 如何通过Python脚本列出Gnu / Linux上的所有打开(X11)窗口? - How can I list all open (X11) windows on Gnu/Linux from a Python script? 如何在 Mac 上的 Python 中列出所有工作区中的所有窗口? - How to list all windows from all workspaces in Python on Mac? 如何从 Windows 中的 Python 脚本创建可在 Mac 上运行的可执行文件? - How to create an executable from a Python script in Windows that can run on a Mac? 如何使用 python 脚本打开 Windows 10 应用程序? - How can I open a Windows 10 app with a python script? 如何从 Python 脚本中列出 Python 可用的所有包/模块? - How can I list all packages/modules available to Python from within a Python script? 如何在 python 控制台中列出所有可用的 Windows 语言环境? - How can I list all available windows locales in python console? 如何从 Mac 的 Spotlight 运行 Python 脚本(而不必打开终端或 Pycharm)? - How Do I Run a Python Script from Mac's Spotlight (Instead of Having to Open Terminal or Pycharm)? 如何通过Python Script Mac在另一个应用程序中打开文档(例如.txt) - How do I open a document (eg. .txt) in another app from a Python Script mac 如何从Windows上开发的Python脚本在Mac上创建可执行文件 - How to create executable file on mac from python script developed on windows 如何从Python脚本中删除所有注释? - How can I remove all comments from a Python script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM