osascript -e "set x to 3"
osascript -e "if x is 5 then"
osascript -e " tell application "System Events" to keystroke return"
osascript -e "end if"
我得到的输出
14:14: syntax error: Expected end of line but found end of script. (-2741)
0:6: syntax error: A “if” can’t go after this “end”. (-2740)
看不出剧本有什么问题。可能是缩进的一些问题。有人在 bash 文件中使用 osascript 吗?
把你所有的苹果脚本行放在一起。这边:
osascript -e "set x to 3
if x is 5 then
tell application "System Events" to keystroke return
end if"
此外,您可以使用所有苹果脚本代码创建如下所示的文件:
#!/usr/bin/osascript
set x to 3
if x is 5 then
tell application "System Events" to keystroke return
end if
我发现这种方式在引用、双引号和转义以及在osascript
中使用bash
变量方面最简单:
#!/bin/bash
# Set bash variable to 3, then use it in osascript
count=3
osascript <<EOF
beep $count
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
EOF
# Continue in bash
echo done