get file path of finder items

here’s a handy trick based on an original post you can find here at Macworld.

There may be times—such as when you’re trying to convey to someone where a file can be found on their machine, or maybe when you’re writing an OS X hints column—when you need to put the path to some file or folder into another document. — Rob Griffiths, Macworld.com

Applescript Iconthe original script does something very simple — a basic task which is missing from OS X — copying the filepath of a selected finder item into a text format. the original script looks like this :

running this script will place text on your clipboard — ready to paste into an email or whatever. the text would look something like this :
/Applications/AppleScript/Script Editor.app
this shows that ‘Script Editor’ can be found in the folder ‘Applescript’ which is in the folder ‘Applications’ — a slash delimited filepath.

you may prefer the more common colon delimited filepath which also shows the home volume — MacGrunt:Applications:AppleScript:Script Editor.app
if so, you’d replace those two lines in the middle with this :

set the clipboard to the selection as text

but here’s another variation which does two additional things :
allows for copying filepaths for multiple items
changes the output to an arrow delimited format

results look more like this :
MacGrunt > Applications > AppleScript > Script Editor.app
MacGrunt > Users > macgrunt > Desktop > Picture 1.png

you can download CopyPath as a finished script here.

now for the cool bit …

Automator Iconhaving to launch an app every time you want to copy a filepath would be a right pain. but you can turn this script into a contextual menu item with automator. here’s how.

prior to OS X 10.6 (Snow Leopard) :
open automator and search for the action “Run Applescript”
drag this action into your workspace
replace the default script with the downloaded one :

then choose File > Save As Plug-in… :

now whenever you want to copy a filepath to your clipboard, simply right-click (or control-click) on the file/s and navigate to the bottom of the contextual menu, like so :

slightly different for OS X 10.6 (Snow Leopard) :
automator changed in 10.6 to include the ‘Service’ option. using this option you’ll see the top of the workspace looks more like this (click to enlarge) :

set the service to allow input from files and folders in the finder.

and for Lion users … :
you guys are so advanced, you’re sure to work it out yourselves.

you’re bound to find many other uses for this handy feature of automator.
have fun.

macgrunt icon

Advertisements

2 thoughts on “get file path of finder items

  1. I was hoping this would work – very useful idea. However using AppleScript Editor (2.2.1) when entering the code and compiling – for some reason the 5th line of code – returns “times” at the end of the line after theSelection. It does compile without error – but creates a Run error – “Can’t find selection”.

    Maybe it’s just a glitch – I checked for typos. Sorry I see you wrote this back in 2011.

    • Thanks for the heads-up Bran
      Looks like I’ll need to rework this post.
      I have a working version of this script that I use all the time.
      Will flick you a copy when I get home tonight (about 14 hours from now)
      m.

thoughtful and respectful comments welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s