在这里很少有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。为make的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单线程,所以文件路径将是内联的,而不是变量。但是我首先移动到命令行,然后移动到脚本编辑器,因为我无法使其工作,并且每个调用此代码片段的方法都会产生相同的错误消息。所以希望当/如果我得到一个脚本的工作,我将能够从Python的osascript调用等效的代码。 :}
它非常有帮助。解决方法和原因。谢谢! – larryy
@larryy太棒了!很高兴我能帮上忙。 – AstroCB
更正:1.冒号分隔的HFS路径是旧的OSX之前的宿醉。AS支持那些向后兼容(和AS AS开发者是懒惰的),并且还支持标准的POSIX路径。 2. Finder期望_object说明符_(例如home文件夹中的“文件”文件的'file“test.txt文件),但会在大部分用例中接受HFS路径字符串(Finder也是旧的OSX之前的宿醉)或”别名“ /'POSIX文件'说明符并转换它们; 'get'和'set'是例外。 3. HFS路径基本上存在缺陷 - 它们无法区分名称相同的卷 - 因此请尽可能使用POSIX路径。 – foo