来自终端 osascript 调用的多个 Applescript 行

Multiple Applescript lines from terminal osascript call

所以我尝试从命令行一次性 运行 多个 Applescript 命令。但是,不管我怎么试,都不行:

$ osascript -e "set x to 0; display dialog x"
$ osascript -e "set x to 0 \n display dialog x"
$ osascript -e "set x to 0 then display dialog x"

有没有办法在不保存到文件的情况下执行此操作?

这对我有用:

osascript -e "set x to 0" -e "display dialog x"

查看 手册页 中的 -e 选项 [=27] 中的 osascript =]航站楼:man osascript

−e statement
Enter one line of a script. If −e is given, osascript will not look for a filename in the argument list. Multiple −e options may be given to build up a multi-line script. Because most scripts use char- acters that are special to many shell programs (for example, AppleScript uses single and double quote marks, “(”, “)”, and “∗”), the statement will have to be correctly quoted and escaped to get it past the shell intact.

你也可以这样做,例如:

osascript <<END         
set x to 0       
display dialog x
END

或者:

osascript -e '          
set x to 0
display dialog x'

您的第二次尝试非常接近正确:

osascript -e "set x to 0 
PRESS ENTER
display dialog x"
PRESS ENTER