Create symbolic links in the Finder via AppleScript

When you work with the command line, you’ll notice that you cannot navigate “into” aliases created with the Finder when in Terminal. For example, you cannot issue a cd command into an alias, because Terminal just doesn’t recognize it is such.

From the command line, however, you can use symbolic links , the Unix equivalent. While you can create these from Terminal using the ln -s command, it is useful to be able to create them from the Finder as well. Here is a simple AppleScript that can do just that.

Paste the following code into a Script Editor window, then save it as an application:

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

If you double-click the resulting AppleScript droplet, it will prompt you to select a file; the script will then create a symbolic link in the same folder where the current file is, and you can move that link wherever you want. If you want to create a symbolic link of a folder, just drag the folder onto the droplet; you can also make multiple symbolic links by dragging them on the droplet at the same time. The script adds a .sym extension to the links it creates, so you can spot them easily.

To comment on this article and other Macworld content, visit our Facebook page or our Twitter feed.
Shop Tech Products at Amazon