Get the path of file onto the clipboard

I find myself needing the path to a file relatively frequently to add to an email or documentation.  I added a service to the Finder contextual menu to get the path to the selected item.  This service notifies me with an alert (just for fun) and can be invoked with a keyboard shortcut.  This was done in Mavericks (10.9).  Most of it should work in 10.8 or 10.7 (except the notification).

To start, open Automator (/Applications/ and choose to make a New Document. When prompted, select to create a Service and click Choose.

Screen Shot 2013-11-05 at 9.12.00 PM

This will create a new workflow that takes the selected items as input.  Change the “Service receives selected” menu to say “Files or Folders” and change “any application” to be “Finder”.

Then we need to add the appropriate actions.

First we need to get the actual path to the selected item. There isn’t an action to do this exactly, so add the Run AppleScript action.  Replace “(* Your script goes here *)” with:

tell application "Finder"
return POSIX path of input
end tell

Then add a Set Variable action and name the variable “myPath”.

Add the Copy to Clipboard action.  Then add the Display Notification.  Enter a Title, like “Path Copied” and for the Message, drag in the myPath variable and add ” is on the clipboard”.

It should look like this:

Screen Shot 2013-11-05 at 9.52.05 PM

Now save this as Copy Path (~/Library/Services/Copy Path.workflow) and try it out in the Finder.

Screen Shot 2013-11-05 at 9.21.06 PMScreen Shot 2013-11-05 at 9.21.03 PM

You should see an alert

Screen Shot 2013-11-05 at 9.21.13 PM

and then be able to paste the path into a text field somewhere.  If you don’t want the alert, then your service only needs the applescript and copy to the clipboard actions.

To add a keyboard shortcut, open System Preferences. Select the Keyboard panel and the Shortcuts tab.  Select App Shortcuts and click the plus sign.

Screen Shot 2013-11-05 at 9.36.58 PM

Set the shortcut to only work in the Finder, enter the title exactly, and put in a keyboard combo to use.

Screen Shot 2013-11-05 at 9.22.59 PM


One thought on “Get the path of file onto the clipboard

Leave a Reply

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

You are commenting using your 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