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

标签 applescript osascript

所以我试图从命令行一次性运行多个 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"

查看终端中osascript手册页中的-e选项 :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'

关于applescript - 来自终端 osascript 调用的多个 Applescript 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69246651/

相关文章:

macos - 从 shell 打开终端并执行命令

Applescript:所有脚本都可以访问的系统范围全局变量

applescript - 使用 Applescript 进行 Photoshop 脚本 — 无法打开 "choose file"的图像

macos - 使用 AppleScript 和 Automator 在 Mac 上使用键盘显示上下文菜单

terminal - Applescript(osascript): opening split panes in iTerm 2 and performing commands

applescript - 绕过AppleScript中的 “Can' t get window”错误

macOS 定期向事件应用程序发送击键

java - 直接在 Java 中获取 Finder 选择,无需任何 Applescript 的帮助

javascript - 如何在提示用户使用 AppleScript 从列表中选择后查找数组中的位置

macos - Alfred:AppleScript 中的工作流程 "Expected end of line"错误