我有一个 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/