Script: Finder/Copy Paths to Selected Items

This is the first in a series of posts about the scripts I use with FastScripts.

  • Script: Copy Paths to Selected Items
  • Application: Finder
  • Suggested key binding: ⇧⌘C

This script copies to the clipboard the paths to the items you currently have selected in the Finder.

If multiple items are selected, all paths are copied, each on a separate line.

If the selection is empty, the path to the active Finder window is used. Said active window may be your Desktop, even though it’s not a traditional window, UI-wise.

Here’s a peek at the code:

finder = Appscript::app("Finder")
paths  = finder.selection.get(:result_type => :alias).map(&:path).join("\n")
paths << finder.insertion_location.get(:result_type => :file_ref).get(:result_type => :alias).path if paths.empty?
open('|pbcopy', 'w') { |io| io.write paths }

To get started, download Copy Paths to Selected Items.rb and put it in your ~/Library/Scripts/Applications/Finder folder. Alternatively, if you’re familiar with git and you currently have nothing in ~/Library/Scripts, you may clone my git repository there and pull whenever I post a new script. I write about using git to track my scripts in more detail here.

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