首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Applescript抛出错误获取活动窗口,“无法获得进程的窗口1”

通过Applescript抛出错误获取活动窗口,“无法获得进程的窗口1”
EN

Stack Overflow用户
提问于 2021-03-15 08:48:58
回答 1查看 785关注 0票数 0

剧本:

代码语言:javascript
复制
global frontApp, frontAppName, windowTitle

set windowTitle to ""
tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontAppName to name of frontApp
    tell process frontAppName
        tell (1st window whose value of attribute "AXMain" is true)
            set windowTitle to value of attribute "AXTitle"
        end tell
    end tell
end tell

return {frontAppName, windowTitle}

它可以工作一些时候,但其他时候我得到的东西如下:[2021-03-15 19:43:53.947] [error] Error: 339:344: execution error: System Events got an error: Can’t get window 1 of process "Adobe Premiere Pro 2020" whose value of attribute "AXMain" = true. Invalid index. (-1719)

有什么想法吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-16 01:46:31

添加到您的repeat loop代码中的下面这个AppleScript代码应该可以做到这一点

代码语言:javascript
复制
global frontApp, frontAppName, windowTitle

set windowTitle to ""
tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontAppName to name of frontApp
    tell process frontAppName
        repeat until exists of ¬
            (1st window whose value of attribute "AXMain" is true)
            delay 0.1
        end repeat
        tell (1st window whose value of attribute "AXMain" is true)
            set windowTitle to value of attribute "AXTitle"
        end tell
    end tell
end tell

return {frontAppName, windowTitle}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66634858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档