我尝试获取应用程序的标题(并将其复制为 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
结果 :
最佳答案
该错误消息表明最前面的应用程序不可编写脚本。
定位不可编写脚本的应用程序窗口的唯一方法是通过 [application] process
上下文中 System Events
对象的属性 - 而不是通过其 application
对象(只有可编写脚本的 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/