我正在尝试从命令行或Python程序创建Finder Alias。我在网上搜索[1] [2] [3]并发现了这一点AppleScript:
$ 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 :(得分: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"'
例如:
$ 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"'
答案 1 :(得分:5)
对于遇到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")'
答案 2 :(得分:1)
此方法适用于命令行:
osascript -e 'tell application "Finder" to make alias file to alias "imac:Users:vy32:current:cyber.txt" at "imac:Users:vy32:foobar"'
foobar
是我homedir中的目录。
答案 3 :(得分:0)
Applescript中的工作命令:
tell application "Finder"
make new alias at POSIX file "/Path/to/location" to POSIX file "/Path/to/file.ext"
end tell
加盐调味。