1
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 吗?

4

2 回答 2

0

我发现这种方式在引用、双引号和转义方面最简单,并bash在以下位置使用变量osascript

#!/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
于 2015-04-29T08:11:48.753 回答
0

Put all your applescript lines together. This way:

osascript -e "set x to 3
if x is 5 then
tell application \"System Events\" to keystroke return
end if"

Additionally, you can create a file like the following with all your applescript code:

#!/usr/bin/osascript
set x to 3
if x is 5 then
    tell application "System Events" to keystroke return
end if
于 2015-04-29T07:59:28.120 回答