Answers:
通过AppleScript在Finder中创建符号链接怎么样 ?
这是该链接中最相关的脚本:
on run
open {choose file with prompt "Choose a file to create a symbolic link:" without invisibles}
end run
on open the_files
repeat with i from 1 to (count the_files)
try
set posix_path to POSIX path of (item i of the_files)
if posix_path ends with "/" then set posix_path to text 1 thru -2 of posix_path
do shell script "ln -s " & quoted form of posix_path & " " & quoted form of (posix_path & ".sym")
end try
end repeat
end open
只需将其粘贴到AppleScript编辑器中并将其另存为应用程序即可。然后,您可以将其拖到搜索器的工具栏上,或将其链接到扩展坞上。
SymbolicLinker可以完全满足您的需求,而且它是免费的。
用户nuc提供的链接上的小程序回答了我的问题。这是在链接消失的情况下复制的小程序。
我更喜欢评论者jonn8n给出的脚本,该脚本也被复制为Macworld文章。
on run
open {choose file with prompt ¬
"Choose a file to create a symbolic link:" without invisibles}
end run
on open the_files
repeat with i from 1 to (count the_files)
try
set posix_path to POSIX path of (item i of the_files)
if posix_path ends with "/" then set posix_path to ¬
text 1 thru -2 of posix_path
do shell script "ln -s " & quoted form of posix_path ¬
& " " & quoted form of (posix_path & ".sym")
end try
end repeat
end open
我使用脚本编辑器将此保存为应用程序,然后将其拖到Finder边栏中,这样我现在可以通过将文件或文件夹拖到应用程序图标上来创建符号链接。
此脚本的可能改进是将运行处理程序更改为使用Finder中当前选择的文件,如下所示:
on run
tell application "Finder" to set sel to selection
open sel
end run
on open the_files
repeat with i from 1 to (count the_files)
try
set posix_path to POSIX path of (item i of the_files as alias)
if posix_path ends with "/" then set posix_path to ¬
text 1 thru -2 of posix_path
try
do shell script "ln -s " & quoted form of posix_path ¬
& " " & quoted form of (posix_path & ".sym")
on error
try
do shell script "ln -s " & quoted form of posix_path ¬
& " " & quoted form of (posix_path & ".sym") with administrator privileges
end try
end try
end try
end repeat
end open
您还可以编辑[application] /Contents/Info.plist以添加
<key>LSUIElement</key>
<true/>
就在最后一个</ dict>之前。这意味着该应用程序将在后台运行,并且在您单击它时不会出现在最前面。
此外,在SymbolicLinker无法使用的Snow Leopard中,您可以使用Automator创建服务以执行Terminal命令或AppleScript来创建符号链接。