【发布时间】:2016-07-24 03:17:39
【问题描述】:
这里很少使用 AppleScript 用户,所以这可能是非常基本的东西,但我似乎无法制作一个非常简单的脚本来创建一个新的别名文件。这是整个脚本:
set source_file to "/path/to/test.txt"
set alias_file to "/path/to/test.txt alias"
tell application "Finder" to make new alias at alias_file to source_file
我已经尝试过使用和不使用“新”。我已经尝试在文件名前面使用“POSIX 文件”并在文件名后面使用“作为 POSIX 文件”作为强制。我尝试过使用“at * to *”和“to * at *”。以防万一目标需要是一个包含文件夹,我已经尝试过了。绝对所有变体都会产生相同的错误消息:
execution error: Finder got an error: AppleEvent handler failed. (-10000)
这并没有告诉我很多。
我显然在这里用“/path/to/”替换了实际文件路径,但我可以保证ls /path/to/test.txt 确认源路径有效,ls "/path/to/test.txt alias" 确认目标路径不存在。
以防万一,我运行的是 Mac OS X 10.11.5。 Finder.sdef 条目确保它看起来像我想要的那样:
make v : Make a new element make new type : the class of the new element at location specifier : the location at which to insert the element [to specifier] : when creating an alias file, the original item to create an alias to or when creating a file viewer window, the target of the window [with properties record] : the initial values for the properties of the element → specifier : to the new object(s)
我真正想做的是从命令行使用 osascript 运行它,而我真正真正想做的是从 Python 调用 osascript 单行,因此文件路径将是内联的,而不是变量。但是我首先转到命令行,然后转到脚本编辑器,因为我无法让它工作,并且调用此代码 sn-p 的每个方法都会产生相同的错误消息。所以希望当/如果我让脚本工作时,我将能够从 Python 的 osascript 调用等效代码。 :}
【问题讨论】:
标签: macos path applescript alias