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

标签 macos applescript

我正在尝试从命令行或 Python 程序创建 Finder 别名。我搜索了网络[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

我做错了什么?

最佳答案

关于您的消息,请尝试查看 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"'

关于macos - 如何从命令行创建 Macintosh Finder 别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7072208/

相关文章:

objective-c - 如何从 Cocoa 调用的管理员权限 bash 脚本获取输出?

applescript - 告诉应用程序 - 字符串与字符串?

macos - 如何在 Mac 上向 Google Chrome 添加启动参数?

shell - 在 Finder 中选择的文件上执行 shell 命令

macos - Excel 保存制表符分隔的文件而不换行 (UNIX/Mac os X)

从 C 调用 Cocoa API

Python IndexError 只发生在 osx 而不是 linux

ruby - Homebrew 软件安装 : Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1

vba - AppleScriptTask 抛出错误 5 - 无效的过程调用或参数

vim - Applescript(如果未添加文件)