osx - Create a symbolic link in the Mac OS X Finder
2014-01
Is there a way to get the same functionality as the unix command ln -s
in the Mac OS X Finder (OS 10.5)? I want to be able to create symbolic links while working in Finder windows without opening the Terminal.
Note that the Make Alias
command in Finder is not what I want because those aliases cannot be navigated in the Terminal (but links created with ln -s
can be navigated by both the Terminal and Finder).
What about that creating symbolic links in the Finder via AppleScript ?
Here's the most relevant script in that link:
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
Just paste it into AppleScript Editor and save it as an application. Then you can drag it over your finder's toolbar or link it on the dock.
SymbolicLinker will do exactly what you're looking for, and it's free.
An applescript at the link provided by user nuc answered my question. Here is the applescript reproduced in case that link disappears.
I preferred the script given by the commenter jonn8n, which was also reproduced as Macworld article.
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
I saved this as an application using Script Editor and dragged the application to the Finder sidebar so I can now create symbolic links by dragging files or folders onto the application icon.
Path Finder adds this to your Finder, and adds a lot more features.
A possible improvement on this script would be changing the run handler to use the currently selected files from the Finder, as so:
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
You could also edit [application]/Contents/Info.plist to add
<key>LSUIElement</key>
<true/>
Just before the last </dict>. This would mean the app would run in the background, and wouldn't come to the front when you clicked on it.
Also, in Snow Leopard where SymbolicLinker doesn't work, you can create a Service with Automator to do either the Terminal command or AppleScript to create a symbolic link.
One more AS:
tell application "Finder"
repeat with f in (get selection)
set p to POSIX path of (f as text)
set p2 to POSIX path of (desktop as text) & name of f
do shell script "ln -s " & quoted form of p & " " & quoted form of p2
end repeat
end tell
Try looking here : http://www.techiecorner.com/528/how-to-create-shortcut-in-mac-os-x/
This is built into OSX already if you press the control key when you click on something.
I created a symbolic link (specifically a symbolic link & not a Finder alias which bash can't follow) to a directory in my home folder using ln -s link $HOME/directory
& now I wish to hide the link in the Finder so I don't have to look at it. Normally I would use chflags hidden link
to accomplish this, but of course that would affect the directory, not the link. I can't use the standard leading dot because the name of the link itself is important for applications that look for it & a leading dot changes the name.
So my question is, how do I hide the symbolic link without hiding the directory it links to or changing its name?
EDIT: I intentionally kept my question vague because it's a small experiment with the Finder, but here's some more details to clarify exactly what I'm trying to do.
Finder uses the $HOME/Desktop folder for the desktop itself, it doesn't matter if it's a link, alias or a completely different folder called “Desktop” (such as the home folder itself) as long as it's in the $HOME directory.
I made a symbolic link to my home directory named “Desktop” in order to populate the contents of Finder's desktop with the contents of my home folder (if you try this, it doesn't take effect until you login again, also this was done on 10.6). That also places the symbolic link itself on my desktop of course which I don't want to see in either a Finder window or on the desktop itself. If I were to rename it to “.Desktop” in order to hide it, it would hide, but the link between my home folder & my desktop would also be broken.
SetFile -P -a V filename
The '-P' flag will make it operate on the symlink and not what it points to. The '-a V' portion will turn on the invisible attribute to hide it in the Finder.
Rename link to .link