我在使用一小部分 Applescript 的 shell 脚本时遇到问题。当我使用 Applescript 编辑器编译它时,它可以工作。它不在 shell 脚本中。
44:49:语法错误:预期的行尾,但找到了命令名称。(-2741) 23:28:语法错误:预期行尾,但在“之后”找到。(-2741)
这是外壳代码:
osascript -e 'tell application "System Events" -e 'activate'
osascript -e 'tell process "Application 10.5" -e 'set frontmost to true' -e 'end tell'
osascript -e 'delay 1' -e 'keystroke return' -e 'delay 1' -e 'keystroke return'
end tell
Applescript(有效):
tell application "System Events"
activate
tell process "Application 10.5"
set frontmost to true
end tell
delay 1
keystroke return
delay 1
keystroke return
end tell
[更新] / [已解决]
这解决了我试图修改applescript以在shell脚本中工作的任何类型的问题:
## shell script code
echo "shell script code"
echo "shell script code"
## applescript code
osascript <<EOF
tell application "Scriptable Text Editor"
make new window
activate
set contents of window 1 to "Hello World!" & return
end tell
EOF
## resume shell script...
您能够将纯applescript 直接放入shell 脚本中,这非常酷。;-)