如何从命令行创建Macintosh Finder别名?

vy3*_*y32 13 macos applescript

我试图从命令行或Python程序创建一个Finder别名.我在网上搜索[1] [2] [3],发现了这一点苹果:

$ 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"'
Run Code Online (Sandbox Code Playgroud)

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

29:133: execution error: Finder got an error: AppleEvent handler failed. (-10000)
Run Code Online (Sandbox Code Playgroud)

[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

我究竟做错了什么?

Eir*_*Nym 9

关于你的消息,试着看看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"'
Run Code Online (Sandbox Code Playgroud)

例如:

$ 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"'
Run Code Online (Sandbox Code Playgroud)


Lea*_*ros 6

对于每个在AppleEvent handler failed错误中挣扎的人:

make alias不像这样ln -s,您不必指定目标文件,而不必指定目标目录,别名的文件名是源文件/文件夹的名称。

例:

osascript -e 'tell application "Finder" to make alias file to (POSIX file "/Applications/Mail.app") at (POSIX file "/Users/leandros/Desktop")'
Run Code Online (Sandbox Code Playgroud)