21

I am working on some long procedures that will need to reference a lot of file paths of documents located locally and on various external drives and servers. In all cases we are using Apple Macs with either El Capitan or Sierra installed.

My problem - it is taking me a long time to manually type and double-check the file paths are correct.

Preferred solution - I would love it if there was just a way to copy and paste the file paths into these procedures.

I did try using the Get Info option, but couldn’t see a file path listed anywhere that I could copy and paste.

I also read this question: Get components (path and filename) of POSIX filepath and did have a go of using the script. This was promising, but it doesn’t quite do what I need.

Is there an easy way for me to just copy and paste file paths as I need them?

For example, if I have an image called “Serial Number.jpg” located on an external drive called Server1 the file path would be: /Volumes/Server1/Serial Number.jpg.

1
  • You used to be able to just use Command+copy and copy the file and paste it into an email, and it would past it in the email as a clickable hyperlink - however I recently updated my Outlook and OS (after not having updated it for at least 2 years) and this hyperlinking capability no longer works. Is this still
    – Aneta
    Commented Mar 26, 2018 at 23:40

8 Answers 8

46

I think this is an option that will do exactly what you want. Using your Serial Number.jpg example, do as follows:

  1. In the Finder browse to the image called “Serial Number.jpg” located on Server1
  2. Right-click on the file to display the context menu
  3. Now press and hold the option key down
  4. Select the Copy “Serial Number.jpg” as Pathname option
  5. Now go to the procedure you’re editing and paste the pathname you just copied

This should result in your document having the /Volumes/Server1/Serial Number.jpg path pasted into it.

Just use the same steps for any file, regardless of whether it’s stored locally, on an external drive, or on a server. This also works to get the file path of folders.

Keyboard shortcut

Thanks to Mateusz Szlosek for pointing out you can also use a keyboard shortcut. Instead of Steps 2 to 4 above, once you've selected the file you can use the option+command+C shortcut to copy the file path. Then you can paste it as usual.

Windows etc files

There are custom built utilities to format shares for other operating systems and sub/afp as well:

10
  • 17
    In addition the full keyboard shortcut to copy file path is ⌥ ALT+⌘ CMD + C, no need to do this using contextual menu. Commented Aug 16, 2017 at 9:24
  • 1
    @MateuszSzlosek “⌥” denotes the option key (the unicode codepoint for this symbol is literally U+2325 OPTION KEY). The word “alt” is additionally screenprinted on the option key on Apple-made keyboards to avoid confusion when using Apple keyboards with other operating systems (since Apple's command key occupies the spot where the alt key is on other keyboards). So in the context of macOS keyboard shortcuts, there is no such thing as “alt”, only option; in the context of Apple keyboards, that key is used for either option or alt, depending on the computer it's plugged into. Commented Aug 16, 2017 at 17:19
  • 3
    alt/opt depends on where you buy your Apple keyboards. The International ones actually say alt, not opt, & have done for at least a decade. the US ones either just have the ⌥ symbol or say both. There's no surprise it's confusing. Ref: support.apple.com/HT201794
    – Tetsujin
    Commented Aug 16, 2017 at 17:31
  • 1
    Is there a resource for all these secret opt reveals? Commented Aug 17, 2017 at 7:04
  • 1
    @geometrikal Ah, okay. Good question. There is the official Mac keyboard shortcuts page that also has links at the bottom to other keyboard shortcut pages, but I'm not sure if there's a single resource for Option key keyboard shortcuts. To be honest, this is just one I accidentally stumbled across one time.
    – Monomeeth
    Commented Aug 17, 2017 at 7:19
28

You can just drag & drop a file [or a whole swathe of them] into a text area to get its [their] path[s] - not in all apps but in many, including Terminal [& incidentally in the question/answer space on Stack Exchange too.]

Some apps, like BBEdit, do not support this and take the contents of the file insteat of the full path. For these apps a Command 'drag & drop' works as well.

3
  • 1
    +1 Good call! I didn't know you could drag and drop into Stack Exchange! :)
    – Monomeeth
    Commented Aug 16, 2017 at 7:51
  • 1
    Thanks for that - this is a great way to copy and paste a folder full of files.
    – ThisClark
    Commented Aug 16, 2017 at 17:17
  • @ThisClark - I'd forgotten you could drag multiple files - added to answer, thanks.
    – Tetsujin
    Commented Aug 16, 2017 at 17:26
3

I would preferable just drag & drop a file into a text area to get its path (see Tetsujin's answer)

If this does not work for you, consider writing a very small program in Qt.

From http://qtsimplify.blogspot.de/2013/01/drag-and-drop-files-into-your.html :

Create a new "Qt Gui Application" in Qt Creator.

Edit the header file, mainwindow.h, by adding the following headers:

#include <QDropEvent>
#include <QUrl>
#include <QDebug>

Reimplement the protected functions, dropEvent() and dragEnterEvent() protected:

void dropEvent(QDropEvent *ev);
void dragEnterEvent(QDragEnterEvent *ev);

In the mainwindow.cpp, add these lines:

void MainWindow::dropEvent(QDropEvent *ev)
{
    QList<QUrl> urls = ev->mimeData()->urls();
    foreach(QUrl url, urls)
    {
        qDebug()<<url.toString();
    }
}

void MainWindow::dragEnterEvent(QDragEnterEvent *ev)
{
    ev->accept();
}

The dropEvent() function is where you recover the name of all the files you drop into your application.

And lastly, add this line into your mainwindow constructor:

setAcceptDrops(true);

Then, e.g. if you want to have the paths in the clipboard, you only need to copy them there using QClipboard

QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(url.toString());

For single file drops, and a list for all files.

3

I use the Services Context Menu "Path to Clipboard" in Finder (although more often I use the Context Menu of QuollEyeTree).

I am not sure if this is a default service, or one I created using Automator (mine is dated 2012), but it is trivial to create such a service, it it does not already exist.

2

A command line solution that I use for getting paths quickly is to use realpath from GNU Coreutils. I have installled coreutils via MacPorts, where the binary is called grealpath. You can then call it on a file and it will give you the path. I like to mix it with pbcopy to quickly get a path into my clipboard: $ grealpath histograms.root | pbcopy

2
  • Why this way as opposed to $ pwd histograms.root | pbcopy?
    – Harv
    Commented Aug 22, 2017 at 17:11
  • That gives you the path of the directory containing histograms.root, rather than the full path of the file itself. You could trivially write a shell script to do it, but I did not.
    – rooms
    Commented Aug 23, 2017 at 18:17
2

There's an app on the app store called "FilePath" IIRC. Click on the file in the GUI then click on the filepath icon and select "copy path" from the menu. It can also copy multiple paths. If you're looking for something quicker I'd imagine you can assign a key combo to the action.

I use this app on a regular basis to share synchronized cloud storage locations with coworkers.

1

Get info (⌘i) of any file or folder.

Triple click on Where under the General category to highlight the path.

enter image description here

Copy (⌘c) this highlighted text and it will put the path on your clipboard.

Close the window (⌘w)

Paste wherever you need to use it (⌘v)

1
  • This is only good for one file at a time.
    – ThisClark
    Commented Aug 16, 2017 at 17:17
1

In a finder window, you can select your file. If you have the gear-looking icon on your finder window you can hold down the option key and click that icon. One available option is to copy pathname. If selected it copies full pathname to the clipboard. You don't have to open the file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .