3

Dragging a folder in Finder while pressing Command + Option ( + ) creates an alias. But is there a quick and similar way to create a symlink this way?

  • 5
    Frustrating, isn’t it? I would prefer a symlink to an alias about 80% of the time. I like the solution from @user3439894, and in combination with a launcher (lots of good, open source ones available), or simply Automator, you can streamline the process very aptly. – CJK Apr 17 at 14:38
  • XtraFinder adds this feature, among other things. It's $5, but has an unlimited (in time and in features) trial. Strongly recommend. – Alexander Apr 17 at 22:29
  • With XtraFinder, Make Symbolic Link is a menu command not a drag and drop. Also XtraFinder requires System Integrity Protection be disabled to install and does not work with macOS 10.12 with SIP enabled nor is it guaranteed to work with OS X 10.11 and macOS 10.13 with SIP enabled. IMO Frankly not worth the hassle! – user3439894 Apr 18 at 11:39
6

macOS does not have a native drag and drop method to create a symlink in the same manner as creating an alias in Finder. By default, symlinks are created by using ln from the command line in Terminal.


In Terminal:

$ ln
usage: ln [-Ffhinsv] source_file [target_file]
       ln [-Ffhinsv] source_file ... target_dir
       link source_file target_file
$

For additional details, use: man ln


For a homegrown solution using Automator and AppleScript, the following is a bare-bones example of an Automator Service (QuickAction in macOS Mojave) that when assigned a keyboard shortcut, e.g. ⌘S in System Preferences > Keyboard > Shortcuts > Services, will create a symlink of the selected items in Finder at the selected destination folder that is brought up by pressing e.g. ⌘S:

This Service (QuickAction) will be available on the Services menu in Finder or from right-click Context menu, and or the assigned keyboard shortcut once an item or items are selected in Finder.

Bare-bones example AppleScript code:

on run {input, parameters}

    if input is equal to {} then return

    activate

    set posixPath to POSIX path of (choose folder with prompt ¬
        "Select destination folder for Symlink..." default location ¬
        (path to desktop folder) with invisibles)

    repeat with thisItem in input
        set thisItem to POSIX path of (thisItem as alias)
        try
            do shell script "ln -s " & quoted form of thisItem & ¬
                space & quoted form of posixPath
        end try
    end repeat

end run

The example AppleScript code assumes you have write privileges at the selected destination folder, other then the selected items source folder, and as coded only creates the symlink if it doesn't already exist. Changes can be made to the code to accommodate other options.

Make Symbolic Link Automator Service


Note: The example AppleScript code is just that and, other then a single try statement, does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.

  • Excellent. Do you think there's perhaps a way to overwrite Finder's native drag and drop behaviour? – TD540 Apr 18 at 9:09
  • 1
    @thomasdecrick, Sorry, no, I do not know of a way to override the default behavior. That said, since one has to press ⌘⌥ and use the mouse anyway, setting up a keyboard shortcut e.g. ⌘S for the Automator Service and some mouse clicks is not a bad alternative. Also, keep in mind that if you already have the destination folder open in another Finder window, you can always drag an drop the folder into the choose folder window to quickly change it to that location and not necessarily have to manually navigate to it. – user3439894 Apr 18 at 13:57
5

The service SymbolicLinker will do what you need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .