Script: Finder/Paste as Symlink

  • Script: Paste as Symlink
  • Application: Finder
  • Suggested key binding: ⌥⌘V

This script creates symlinks to the paths in the clipboard in the active Finder window. The target path used for these symlinks is relative to the location where we’re creating the link.

It supports paths copied via ⌘C in the Finder, or a list of plain text paths as you’d get from my previous Copy Paths to Selected Items script. The pasting behaviour is generally similar to what you’d get with file copies using ⌘V. E.g. the name used is the same as the source’s, numbers are appended to prevent name collisions, etc.

Unfortunately, AppleScript pretty much sucks ass, so in order to be able to read multiple paths from the clipboard I had to resort to some good old Cocoa. But hold your brackets; I used MacRuby.

If you’re not using MacRuby for anything already (shame on you), you probably don’t have it installed. MacRuby 0.7 was just released right after I initially posted this, so go ahead and grab it while it’s fresh. It’s a standard OS X Installer package, no neck beard or dark chanting needed.

Seemingly, anything touched by Cocoa becomes automatically verbose; so I’ll not be showing the script in its entirety here. However, here’s a peek at the Cocoa bit:

paths_from_clipboard = NSPasteboard.generalPasteboard.pasteboardItems
  .map { |pbi | pbi.stringForType('public.file-url') }.compact
  .map { |url | NSURL.URLWithString(url).path }
  .map { |path| }

You can see it in all its colorful glory here.

(In all fairness, Cocoa is not really to blame for the length, it just turned out longish.)

As usual: get the standalone script file, or git pull if you’re keeping a git clone of the scripts.

This post of part of series on the scripts I use with FastScripts.

Got comments? Use reddit and/or poke me on twitter.