Create a symbolic link in the Mac OS X Finder

39

16

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).

Michael Schneider

Posted 2009-08-18T09:16:21.060

Reputation: 533

macOS really ought to provide this as an opt-in feature for power users. – Andy – 2019-01-13T06:13:14.823

Answers

16

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.

nuc

Posted 2009-08-18T09:16:21.060

Reputation: 330

Your link is rotten – Ben Leggiero – 2015-10-28T16:48:55.620

2The 2nd comment at that link, left by jonn8n, gives exactly the functionality I was looking for. Although, I'm a bit surprised this is not possible within Finder itself. – Michael Schneider – 2009-08-18T11:09:30.740

27

SymbolicLinker will do exactly what you're looking for, and it's free.

alt text

arathorn

Posted 2009-08-18T09:16:21.060

Reputation: 8 559

3FWIW, SymbolicLinker still works in Mavericks 10.9.3. – martineau – 2014-06-28T16:03:47.030

1

Your link is dead. Did you link to this? http://www.macupdate.com/app/mac/10433/symboliclinker

– Ben Leggiero – 2015-10-28T16:48:37.597

SymbolicLinker is dead, at least as of Mavericks. – Dave Land – 2018-12-18T00:18:19.633

Just a note to confirm that this still works on Mojave. Also worth noting that the Releases tab on the linked Github site has a .dmg with the service and installation instructions to save building it yourself. – Robin Macharg – 2019-06-21T06:29:19.913

2

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.

Michael Schneider

Posted 2009-08-18T09:16:21.060

Reputation: 533

1

Use Automator.app to create a Service that executes a bash script. This is simpler than AppleScript and more reliable than installing third-party software.

for f in "$@"
do
    ln -s "$f" "$f.symlink"
done

Make Symbolic Link.workflow

Then you can access the Make Symbolic Link command under the Services menu:

enter image description here

The result:

enter image description here

Quinn Comendant

Posted 2009-08-18T09:16:21.060

Reputation: 771

1

Path Finder adds this to your Finder, and adds a lot more features.

Khaled Kammar

Posted 2009-08-18T09:16:21.060

Reputation: 11

0

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.

Benjamin Dobson

Posted 2009-08-18T09:16:21.060

Reputation: 1 021

0

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

Lri

Posted 2009-08-18T09:16:21.060

Reputation: 34 501

0

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.

beiju

Posted 2009-08-18T09:16:21.060

Reputation: 1 151

1Actually SymbolicLinker does work on Snow Leopard since, at least december 2009. – cregox – 2011-03-03T12:22:44.457

-1

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.

Ben G

Posted 2009-08-18T09:16:21.060

Reputation: 1

5Only it's not a symbolic link that's created. You can cd into a symbolic link to a folder, but not into a Finder alias. Read the question, it already states this. (Moderators: We might want to leave this non-answer in, to prevent further answers along this line) – Daniel Beck – 2011-03-08T09:14:40.003

5@daniel I doubt it will help much preventing, as answers in this line typically come from non-reading-people. :P – cregox – 2011-03-08T17:45:42.667