Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何从命令行创建Macintosh Finder别名?_Macos_Applescript - Fatal编程技术网

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

Macos 如何从命令行创建Macintosh Finder别名?,macos,applescript,Macos,Applescript,我正在尝试从命令行或Python程序创建查找器别名。我在网上搜索了[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"' tell application "Finder" ma

我正在尝试从命令行或Python程序创建查找器别名。我在网上搜索了[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"'
tell application "Finder"
    make new alias at POSIX file "/Path/to/location" to POSIX file "/Path/to/file.ext"
end tell
不幸的是,它给了我这个错误:

29:133: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[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"'
tell application "Finder"
    make new alias at POSIX file "/Path/to/location" to POSIX file "/Path/to/file.ext"
end tell

根据口味添加盐。

此方法通过命令行工作:

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

其中
foobar
是my homedir中的一个目录。

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

对于所有正在使用
AppleEvent处理程序失败的人,错误:

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")'

出于兴趣,“启用辅助设备访问”是否已打开?我想你把
切换到了
属性。@Phillip Regan不需要实际的别名引用吗?@fireshadow52:no。我抓取了一个随机文件的路径,并使用了我的主文件夹(在那里我只存储操作系统的默认值),它只是工作(没有双关语);在我指定的位置出现了一个别名。我确实希望能够从命令行执行此操作,但当我将您的代码更改为
osascript-e'时,告诉应用程序“Finder”为
,然后是第二行,它就不起作用了@vy32您是否尝试将
更改为
\”
?@fireshadow52,
位于
内部,因此它可以不经更改地通过。其他示例对我来说不起作用,但此示例使用老式的“Mac OS”“文件路径不起作用。谢谢。这是@Leandros指出的一个错误,他的解决方案实际上是有效的…@MarkSetchell你能告诉我更多关于你的环境吗?你好。我在iMac上运行OSX El Capitan,我得到了与Leandros指出的完全相同的错误。我明白了。我已经让它使用
osascript-e'告诉应用程序“Finder”将别名文件转换为POSIX文件“/Applications/Xcode.app/Contents/Applications/Instruments.app”at POSIX文件“/Users/mylogin/Applications”
更多说明:第一个参数是原始文件或文件夹。第二个参数是将在其中创建别名的文件夹。此文件夹必须已存在。您不能命名别名,它将在第一个参数中简单地被赋予文件或文件夹的名称(您可以在以后重命名它)。