Subscribe to MacYourself via RSSFollow MacYourself on Twitter

Copy file or folder path to the clipboard in Mac OS X Lion

Copy file or folder path to the clipboard in Mac OS X Lion

Learn how to create your own OS X service that lets you copy & paste the paths of files and folders in Finder. After just a few steps you will be able to select items in Finder, press a quick keyboard shortcut, and paste the path(s) anywhere you want.

Mac users have long complained that there’s no easy way to copy the location of a file or folder on their computer and paste it in a document, email, internet browser, etc. There are a bunch of third party utilities and convoluted workarounds to get this functionality, but let’s be honest – they’re all pretty terrible. Even MacYourself’s clever workaround from 2009 doesn’t work anymore in OS X 10.7 Lion.

So what do we do? We take matters into our own hands, of course! Let’s come up with our own solution – and let’s make it awesome.

Before we get started, we should establish some goals. Obviously we want to copy a file path or folder path from Finder and paste it somewhere else for reference. Let’s take that a few steps further and say we want to:

  • Support the selection of multiple files and folders at a time
  • Require no third party software or plugins to accomplish our goal
  • Integrate with Finder so this feels like a real, native solution
  • Set up a keyboard shortcut for quick & easy access
  • Copy the path to OS X’s clipboard so it can be pasted in any application

Sounds like a plan! Here we go…

  1. Launch Automator from your Mac’s Applications folder. If you’ve never used Automator before, that’s not a problem. This is going to be so simple anyone can do it.
  2. Double-click the Service icon from Automator’s start menu.
    Copy file path to clipboard in Mac OS X 10.7 Lion
  3. Toward the top of the right column, you’ll see this line of text: “Service receives selected _____ in _____”. Choose “Files or Folders” from the first menu and “Finder” from the second.
  4. Next, click on Utilities in the Actions library on the left side. Double-click “Copy to Clipboard” in the middle column. You’ll notice that this action has been added to our workflow on the right.
    Copy folder path to clipboard in Mac OS X 10.7 Lion
  5. Go to File > Save in the menu bar and name your service Copy File Path. Our work with Automator is now done, so you can safely quit it once the service is saved.
  6. Launch System Preferences and go to the Keyboard pane. Click on the Keyboard Shortcuts tab.
  7. Select “Application Shortcuts” from the list on the left. Next, click on the + button at the bottom of the list.
  8. A small window will come up with a few options that need to be set. Select “Finder” from the Application menu, type Copy File Path as the Menu Title, and create your own Keyboard Shortcut. If you don’t know what to put here, you can just press Shift+Command+C on your keyboard. Click Add and we’re done!
    Copy file path to clipboard in Mac OS X 10.7 Lion

Now let’s test our fancy solution! Here’s how it works…

  1. Select any file or folder (or a mixture of multiple files and folders at once) in Finder.
  2. Press your keyboard shortcut – in our case, Shift+Command+C. This copies the path to OS X’s clipboard.
  3. Open a text document, email message, or other place you’d like to use your location path. Press Command+V (or right-click and select Paste) to paste the file path(s). Hopefully you should see something like /Users/YourName/Documents/Work/Files/resume.doc

From now on these 3 easy steps are all you have to do to copy and paste file paths from Finder to your clipboard and, ultimately, another application. Pretty cool!

A few things to mention… If you’re not keen on keyboard shortcuts, the service you created is also accessible when you right-click on an item in Finder and select Services > Copy File Path from the contextual menu. The actual file we created for this service is located in: ~/Library/Services in case you ever want to delete it or copy it to put on another Mac. Finally, this tutorial was written specifically for Mac OS X 10.7 Lion, so the steps involving Automator might be a little different if you’re running an older version.

How does this solution work for you? Does it give your Mac the functionality you were looking for?

79 Comments Have Been Posted (Leave Your Response)

Brilliant!! Thank you so much!

Thanks a lot. Works great.

I’ll start using Automator way more !

brilliant! thank you! thank you!

Works pretty nicely. I found that if you need the directory, select a file within the directory and use the shortcut you created, paste where you need it, and just delete the file works well (although, a little more inconvenient). I haven’t the time to figure out how to do it right.
It’s interesting that whatever file you last selected (and path copied to clipboard?) is what is pasted even if you select another directory (not a file) and use the keyboard shortcut. I haven’t tried the Services menu.

it does copy all the files if i have selected more than one file. i’m in the icon view in finder. if i select file 1, it copies that path, file 2 it copies that one. now if i select file 1 and file 2 it only copies file 1

Shift Command G in the save as/ open file dialog shows the Goto folder, do not need to drag and drop it. http://hints.macworld.com/article.php?story=20031019213055945

How about when there are spaces in the path? On Windows, I can start the path with a quote(“) and end with a quote and it makes it a hyper link. Any suggestions?

This is EXACTLY what I wanted!! Thank you SOOO much!!!

Thank you. Can’t tell you how much I appreciate a quick and clear solution. You Rock!

I can’t seem to get this working if there is a space in directory path, eg

/Users/johnq/Documents/A new approach to getting fit.xmind

doesn’t work but but it works fine with

/Users/johnquirke/Documents/Doc1.doc

I have tried adding this sed script to replace the space with %20 but it doesn’t work – any thoughts?

sed -e ‘s/[ ]*/%20//g’

Dude.. A miracle, that’s exactly what I wanted!

yo – this is great but can you please answer the question of getting the Server Path? this works fine for the Volume path but you can’t send those for someone sharing a network to click on and get the file… you need the AFP or Server path!

It works!
Thanks for sharing with us! :)

This works and combined with cmd-shift-G lets me paste a file path in a good enough way.

This should be standard of course, like it was in XP. Microsoft don’t get EVERYTHING wrong. They just tend to change the stuff they get right in the next release!

This is the best post in the history of posts. Thank you, thank you, thank you.

Or you can hit command+i with the file selected and copy the path under General –> Where.

[…] Setting this up is a bit more complex and requires the first 5 steps from Copy file or folder path to the clipboard in Mac OS X Lion | MacYourself: […]

Thank you for this great, detailed tutorial!!
I have the same question as Mike’s

I want to prepend “file://” to the file path, I guess I need to deal something with “Run Shell Script”? so I can set up another shortcut to copy the file path as “file:///Users/jMara/Documents/Doc1.doc”.

Please help me with this!!! Thanks again!

This is fabulous, Although the key “command+shfit+c” does NOT work for me, the “copy file path” option appears under “services”, when I simply right-click on the file name, in the Finder window.
Thank you so vey much for sharing.

Its really awesome. Thank you very much

This was the first time I felt capable as I got it to work in a plain word doc as I tested it! THEN… I went to my project and tried and now –lost.
Here is what I’m trying to get done:
I have a document that I actually send to clients as a PDF when it’s completely ready. Inside that doc is a schedule of activities that I want to have people be able to click for the details and instructions of that activity, ie. “Warm UP” then when they click it, it shows that plan in PDF form. When they click “MAIN ACTIVITY” then my pdf comes up with that specific page… Do I hightlight the name of the activity, then ‘hyperlink it’ then paste the path? WHat if the name of the activity is not my name like it came up when I practiced your steps?

thanks for the advice. it’s great but when I try to open the link, rather than opening the file I want, it tries to open it as a web page in chrome…am I doing something wrong? Many thanks!

spaces and other reserved characters like & need to be prepended (escaped) by a \ (backslash) e.g.

/Volumes/My\ Data/random_stuff_\&_research

a server volume needs to be mounted before you can use the path above, I’ve used a shell script –
#!/bin/sh
# create mount dir
mkdir /Volumes/MyData
# mount MyData to mount dir (replace user, pass and server or leave out user/pass for guest connection)
mount_smbfs smb://user:pass@server/MyData /Volumes/MyData
# open folder or file
open /Volumes/MyData/random_stuff_\&_research

Alternatively, use an alias

Create an alias by holding cmd+alt+shift and then dragging the folder/server to your Desktop/Documents/… – you can then use the alias to mount the server volume.

Leah – if you’re linking to inside a pdf, you’re in the wrong place, use google “link inside pdf”. If you’re linking to other pdfs, you can get the path of the other pdf as described, but this may not work on other filesystems (and I’m not sure how to do relative paths).

Long Path Tool works well to copy or delete long path files, you may use it and I m sure you will love it.

Ant, great post – thank you for taking the time. I am having trouble with using this for multiple files (3-10) and pasting on Excel. Excel does not accept the contents, Word appears to complain that not enough memory space is available and Text Wrangler is only taking the first link. Ay suggestions?

Still works for Mavericks OS X 10.9.5. Thanks — that was easy.

If you want to use it in Evernote, use the Copy File Path on the file, then simply click on your note, use the shortcut command-k (which you also use to paste website URLs), and paste the path in the box. For Evernote use, you’ll need to insert File:// in front of the path (no spaces). This will OPEN the file.

If you just want to see the file in Finder then Copy File Path for the folder containing the file. Same procedure, and again, insert File:// at the start. I suppose there’s a way to use Automator to get the File:// inserted automatically, but that’s for after this report is done!

Thanks again. Very clearly written, easy-to-follow steps.

PS Evernote generates a security warning when you click on your link — just tell it Okay after checking Don’t Bug Me Again.

It runs!. Perfect I’m very grateful

This is a big problem. This type of long path problem can be solved by using Long path tool.

Thanks a lot, your instructions are very clear! But… it does not work on my Mac. It create something like this in the Clipboard:

/Users/JS/Dropbox (XXX)/_XX Confidential/_Client documents etc/_YYY/_Agreed documents/Service workflow 5.10.pdf

But when I paste it in an email after having written text, selected it and Cmd-K’ed it, I can’t click on the OK box.

Help :-)