【问题标题】:Mac - List opened windows in terminalMac - 列出终端中打开的窗口
【发布时间】:2012-04-24 20:19:36
【问题描述】:

我想在终端中列出打开的窗口以获取 x、y、宽度和高度,如 X11 的 xwininfo -root -tree

我试过了:

osacript -e tell application "Microsoft Word" to get the bounds of the front window

但它不适用于所有应用程序,并且您不能指定子级(如果您有两个 Word 文档,它会返回第一个打开的文档)。

【问题讨论】:

    标签: macos applescript osascript


    【解决方案1】:

    获取所有窗口的位置:

    osascript -e 'tell application "System Events" to get the position of every window of every process'
    

    尺寸:

    osascript -e 'tell application "System Events" to get the size of every window of every process'
    

    标题:

    osascript -e 'tell application "System Events" to get the title of every window of every process'
    

    查看 AppleScript 编辑器中的参考以获取更多属性。

    【讨论】:

    • 谢谢,但它不起作用。当我尝试:osascript -e '告诉应用程序“系统事件”以获取每个进程的每个窗口的位置'时出现此错误:执行错误:系统事件出错:辅助设备的访问被禁用。 (-25211)
    • 进入系统偏好设置 -> 通用访问并启用“启用辅助设备访问”
    • 非常感谢!最后一个问题,我如何确定窗口是在 Dock 中(隐藏)还是在前面?
    • 我发现我还必须重新启动终端 (iTerm) 才能获得许可 (Big Sur)
    猜你喜欢
    • 1970-01-01
    • 2010-11-12
    • 2020-06-05
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 2014-07-20
    • 2010-12-20
    • 1970-01-01
    相关资源
    最近更新 更多