macos - 为什么这个简单的 AppleScript 不起作用?

标签 macos bash shell alias osascript

我有一个 Shell 脚本,我需要在 MacOSX 10.6.X 上创建别名文件夹,所以我调用 osascript 来使用下面的代码来完成它:

Source="/Volumes/Test Project/Folder/SubFolder"
Destination="/Volumes/Test Project/Dest/"

/usr/bin/osascript -e 'tell application "Finder" to make alias file to POSIX file "$Source" at POSIX file "$Destination"'

此代码返回:

29:103: execution error: Finder got an error: AppleEvent handler failed. (-10000)

有没有人有解决办法?

最佳答案

Shell 不会替换单引号字符串(例如整个 AppleScript 命令)内的变量(例如 $Source)。解决方案:在命令周围使用双引号(这意味着您需要使用反斜杠转义其中的双引号)。

/usr/bin/osascript -e "tell application \"Finder\" to make alias file to POSIX file \"$Source\" at POSIX file \"$Destination\""

关于macos - 为什么这个简单的 AppleScript 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11165799/

相关文章:

swift ,macOS : Open terminal window at the location

java - 当 JOptionPane 显示在 ChangeListener 上时,JSpinner 不断旋转

linux - 如果您失去 Internet 连接,在服务器上运行的命令会发生什么情况?

shell - 将 nmap 输出发送到文件而不将其打印到标准输出

bash - 比较输出而不是命令

css - 如何使用 sed 编辑 css 文件中的字体大小和字体系列选项?

git - 使用 awk sed 解析更新 puppet 文件

cocoa - 在使用 Core Data 和推出自定义模型之间做出决定的因素有哪些?

swift - 使用 WKWebView 输入类型=文件上传文件不会打开文件对话框

python - TensorFlow安装问题Mac