osascript语法错误“期望的表达式,但找到了行尾-2741”

问题描述

我正在编写一个使用AppleScript的bash脚本,该脚本禁用了麦克风和摄像头,然后单击Google Meet Web页面上的“立即加入”按钮。禁用麦克风和摄像头的部分可以正常工作,但是我在脚本部分中想要单击“加入”按钮时遇到了问题。这是脚本:

#!/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)

如何解决错误并使脚本正确执行(单击按钮)?

解决方法

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

tell active tab of window 1 to -

使用:¬,例如:

tell active tab of window 1 to ¬

行继续符可以通过在脚本编辑器中键入选项 L 来创建。

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

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