首页 > 解决方案 > 使用 AppleScript 获取 Finder 打开的应用程序的 UI 元素

问题描述

set classNames to {}
tell application "Finder"
    tell front window of (first application process whose frontmost is true)
        set uiElems to entire contents as list
    end tell
end tell

当我在脚本编辑器中运行它时,它返回:

{group 1 of window "test" of application process "Script Editor" of application "Finder", pop up button 1 of group 1 of window "test" of application process "Script Editor" of application "Finder", pop up button 2 of group 1 of window "test" of application process "Script Editor" of application "Finder", checkbox 1 of window "test" of application process "Script Editor" of application "Finder", checkbox 2 of window "test" of application process "Script Editor" of application "Finder", checkbox 3 of window "test" of application process "Script Editor" of application "Finder", busy indicator 1 of window "test" of application process "Script Editor" of application "Finder", static text "Running…" of window "test" of application process "Script Editor" of application "Finder", splitter group 1 of window "test" of application process "Script Editor" of application "Finder", splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", scroll area 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", text area 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", scroll bar 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", splitter 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", group 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", static text "Result" of group 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", text area 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", scroll bar 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", splitter 1 of splitter group 1 of window "test" of application process "Script Editor" of application "Finder", toolbar 1 of window "test" of application process "Script Editor" of application "Finder", button 1 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", button 2 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", button 3 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", button 4 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", group 1 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", group 1 of group 1 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", checkbox 1 of group 1 of group 1 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", checkbox 2 of group 1 of group 1 of toolbar 1 of window "test" of application process "Script Editor" of application "Finder", static text "—" of window "test" of application process "Script Editor" of application "Finder", button 1 of window "test" of application process "Script Editor" of application "Finder", button 2 of window "test" of application process "Script Editor" of application "Finder", button 3 of window "test" of application process "Script Editor" of application "Finder", menu button "Edited" of window "test" of application process "Script Editor" of application "Finder", image "test" of window "test" of application process "Script Editor" of application "Finder", static text "test" of window "test" of application process "Script Editor" of application "Finder"}

但是当我尝试将脚本作为应用程序运行并尝试通过 Finder 打开应用程序时,错误是:

无法获取最前面 = true 的应用程序进程 1 的窗口 1。无效索引。(-1719)

有人可以帮忙吗?我是 AppleScript 的新手,没有任何线索。

标签: applescript

解决方案


推荐阅读