首页 > 解决方案 > osascript 语法错误“预期的表达式,但发现行尾。(-2741)”

问题描述

我正在编写一个使用 AppleScript 禁用麦克风和摄像头的 bash 脚本,然后单击 google meet 网页上的“立即加入”按钮。禁用麦克风和摄像头的部分运行良好,但我遇到了用于单击加入按钮的脚本部分的问题。这是脚本:

#!/bin/bash

osascript <<EOF

tell application "System Events"

    delay 4

    key code 14 using command down 
    delay 1 

    key code 2 using command down
    delay 1 

end tell

EOF

#the following is not working- 

osascript <<EOF

tell application "brave" 
  tell active tab of window 1 to - 
  execute JavaScript "document.getElementById('Join now')[0].click();" 
end tell 

EOF

当脚本的第二部分尝试执行时,我收到此错误:

62:63:语法错误:预期表达式但找到行尾。(-2741)

如何修复此错误并让脚本正确执行(单击按钮)?

标签: bashsyntax-errorapplescriptosascript

解决方案


之后您没有正确的行继续符to

tell active tab of window 1 to -

使用:¬,例如:

tell active tab of window 1 to ¬

可以通过在Script Editor中键入来创建行继续符optionL

如果仍然抛出错误,则将其全部放在一行中,例如:

tell active tab of window 1 to execute JavaScript "document.getElementById('Join now')[0].click();" 

推荐阅读