gpt4 book ai didi

windows - AppleScript 获取窗口的标题

转载 作者:可可西里 更新时间:2023-11-01 10:05:03 33 4
gpt4 key购买 nike

我尝试获取应用程序的标题(并将其复制为 var)到目前为止,这是我的代码,但这是失败的

tell application "app"
activate
end tell

tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell

tell application frontApp
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell

结果:

error "app got an error: every window doesn’t understand the “count” message." number -1708 from every window

最佳答案

错误消息表明最前面的应用程序不是可编写脚本的

针对非脚本化应用程序窗口的唯一方法是通过 System Events 上下文中的 [application] process 对象的属性 - 不是 通过它的 application 对象(只有 scriptable application 对象有 windows 元素):

tell application "app"
activate
end tell

tell application "System Events"
# Get the frontmost app's *process* object.
set frontAppProcess to first application process whose frontmost is true
end tell

# Tell the *process* to count its windows and return its front window's name.
tell frontAppProcess
if count of windows > 0 then
set window_name to name of front window
end if
end tell

关于windows - AppleScript 获取窗口的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33420848/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com