如何通过Python脚本列出Mac上所有打开的窗口? [英] How can I list all open windows on Mac from a Python script?

查看:86
本文介绍了如何通过Python脚本列出Mac上所有打开的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从Python脚本中获取在macOS/OS X上打开的所有窗口的列表.这将是Win32的 EnumWindows API调用.

I'd like to be able to grab a list of all windows that are open on macOS/OS X from a Python script. This would be the Mac equivalent on win32's EnumWindows API call.

理想情况下,我希望能够使用它来获取每个打开的窗口的标题/标题文本以及位置/大小信息的列表.

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.

是否存在将返回此信息的OS或Cocoa API调用?

Is there an OS or Cocoa API call that will return this info?

推荐答案

您可以使用 pyobjc .这应该为您获取标题名称:

You can use pyobjc. This should get the title names for you:

from AppKit import NSWorkspace
[apps["NSApplicationName"] for apps in NSWorkspace.sharedWorkspace().launchedApplications()]


更多背景知识: pyobjc 使用石英窗口服务" ,这是他们用于在Mac OS上管理应用程序窗口的程序.


A little more background: pyobjc is implemented using Quartz Window Services, which is the program they used to manage application windows on Mac OS.

这篇关于如何通过Python脚本列出Mac上所有打开的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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