windows - AppleScript 获取窗口的标题

标签 windows applescript title

我尝试获取应用程序的标题(并将其复制为 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/

相关文章:

具有枚举值的 C# Propertygrid 组合框(Win Forms)

objective-c - Mac 应用程序中的 Facebook

macos - iTunes Scripting Bridge - 如何播放特定轨道

Php - 变量中的标题(不工作)

iphone - 如何在 iPhone 中设置 Tabbar 集成?

java - 获取 Mac 中运行的驱动程序

c++ - Windows 的原始鼠标输入

windows - 抽取 Assets :precompile doesn't work (rails 3. 1.1)

macos - 是否可以授予沙盒应用程序访问从 AppleScript 发送的文件的权限?

android - 如何为自定义微调器设置默认标题?