首页 > 解决方案 > 预期的行尾,但在脚本编辑器中找到标识符

问题描述

我正在尝试右键单击应用程序“Pro Tools”中的按钮。

为此,我试图告诉脚本编辑器/苹果脚本使用向下控制来单击按钮(模拟 Mac 上的右键单击)。但是,当我尝试编译或运行代码时,我不断收到错误消息。我收到一条语法错误消息,上面写着

预期的行尾等,但找到了号码。

或者

预期的行尾,但找到了标识符。

那点使用。

tell application "System Events"
    tell application process "Pro Tools"
        click button "Record Enable" of group "Normal Transport Buttons" of group "Transport View Cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" using key code 59
    end tell
end tell

我也尝试过使用这段代码:

tell application "System Events"
    (click button "record enable" of group "normal transport buttons" of group "transport view cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" of application process "Pro Tools")
    using key code 59
end tell

标签: applescript

解决方案


首先,如果你使用嵌套的tell块,你会让你的生活更轻松,就像这样:

tell application "System Events"
    tell application process "Pro Tools"
        tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
            tell group "Transport View Cluster"
                tell group "Normal Transport Buttons"
                    click button "Record Enable"
                end tell
            end tell
        end tell
    end tell
end tell

占用更多空间,是的,但它更容易调试。

话虽如此,您可以尝试使用perform命令而不是clickor key code。我的意思是,如果有一个等价的键可以右键单击最简单的按钮,只需使用:

tell application "System Events"
    tell application process "Pro Tools"
        key code 59 using control down  *-- or whatever*
    end tell
end tell

但如果没有,请先尝试:

tell application "System Events"
    tell application process "Pro Tools"
        tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
            tell group "Transport View Cluster"
                tell group "Normal Transport Buttons"
                    tell button "Record Enable"
                        log properties
                        log actions
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

如果日志显示按钮的操作似乎是正确的,您可以使用以下命令直接调用它:

                tell group "Normal Transport Buttons"
                    tell button "Record Enable"
                        perform action 2 *-- or whatever*
                    end tell
                end tell

如果没有更多信息,很难说更多……


推荐阅读