2011-08-16 27 views
9

我试图从命令行或从Python程序创建Finder别名。我已经在网上搜索[1] [2] [3],发现的AppleScript此位:如何从命令行创建Macintosh Finder别名?

$ osascript -e 'tell application "Finder" to make new alias at POSIX file "/Users/vy32/cyber.txt" to POSIX file "/Users/vy32/a/deeper/directory/cyber.txt"' 

不幸的是,它给了我这个错误:

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

[1] http://hayne.net/MacDev/Bash/make_alias

[2] https://discussions.apple.com/thread/1041148?start=0&tstart=0

[3] http://hintsforums.macworld.com/showthread.php?t=27642

我做错了什么?

+0

出于兴趣,是 “启用辅助设备的访问” 打开了吗? http://hints.macworld.com/article.php?story=20060203225241914 – Coxy

+0

我认为你把'at'和'to'转换为attribtutes。 – fireshadow52

回答

7

关于您的消息,请尝试查看Console.app。可能是源文件不存在。当我尝试使Xcode 4.3+应用程序可见时,这可以帮助我。我发现工作代码:

$ osascript -e 'tell application "Finder" to make alias file to POSIX file "/file/to/make/link/from" at POSIX file "/folder/where/to/make/link"' 

例如:

$ osascript -e 'tell application "Finder" to make alias file to POSIX file "/Applications/Xcode.app/Contents/Applications/OpenGL ES Performance Detective.app" at POSIX file "/Users/mylogin/Applications"' 
+0

工作正常!谢谢。 – vy32

+0

@Leandros指出了一个错误,他的解决方案实际上可行...... –

+0

@MarkSetchell你能告诉你更多关于你的环境吗? –

0

在AppleScript的工作命令:

tell application "Finder" 
    make new alias at POSIX file "/Path/to/location" to POSIX file "/Path/to/file.ext" 
end tell 

加入盐调味。

+0

@Phillip Regan不需要实际的别名引用吗? – fireshadow52

+0

@ fireshadow52:没有。我抓住了一个随机文件的路径,并使用我的家庭文件夹(我只存储操作系统的默认设置),它只是工作(没有双关语意图);一个别名出现在我指定的位置。 –

+0

我真的希望能够从命令行执行此操作,但是当我拿到代码并将其更改为'osascript -e'将应用程序“Finder”更改为'后跟第二行时,它不起作用...? – vy32

1

这种方法在命令行工作:

osascript -e 'tell application "Finder" to make alias file to alias "imac:Users:vy32:current:cyber.txt" at "imac:Users:vy32:foobar"' 

foobar是我的主目录的目录。

+0

其他例子对我来说不起作用,但是这个用旧式“Mac OS”文件路径。谢谢。 – 2014-04-16 17:28:05

3

为大家的AppleEvent handler failed错误挣扎:

make alias并不像ln -s工作,你不必指定目的地文件,您必须指定目的地目录,别名的文件名是源文件/文件夹。

例子:

tell application "Finder" to make alias file to (POSIX file "/Applications/Mail.app") at (POSIX file "/Users/leandros/Desktop")