Apple - Copying the current directory's path to the clipboard

Option+Command+C

Will copy the path for selected folder or file to the clipboard. Tried on El Capitan.


You can use Automator to do this with a single keyboard shortcut that you can use from any app, and without installing 3rd party software.

This Automator Service will copy the path of the Finder's front window, rather than the path of a selected file or folder, so it won't affect what windows are open or what items are selected. The path that is copied is simply text, so it can be pasted anywhere that you can paste text.

  1. Open Automator and create a new Service.
  2. Change "Service receives selected" to no input (or "files or folders" to have it appear from a right click) and leave it set to any application (unless you only want it to work from a specific app, like the Finder).
  3. Add a "Run AppleScript" action to the workflow.
  4. Replace (* Your script goes here *) with:

    try
        tell application "Finder" to set the clipboard to POSIX path of (target of window 1 as alias)
    on error
        beep
    end try
    
  5. Save the Automator Service with whatever name you'd like it to have in the Services menu.

This Automator Service will now be in your Services menu.

Note: This doesn't escape spaces, so if your path has spaces, you may need to quote it. For example, in Terminal, the path would need to be quoted, but in Finder's "Go to Folder" command, it would not. If you want it to copy as quoted, you can change POSIX path to quoted form of POSIX path.

Copy Finder Window Path Service

You can add a keyboard shortcut for the service by going to System Preferences > Keyboard > Keyboard Shortcuts, then click on "Services" in the left pane, then scroll down to the "General" section in the right pane until you find your service.

Copy Finder Window Path Keyboard Shortcut


Next to the name of the folder in the Finder is an icon depicting that folder. This icon can be dragged to anywhere you need to accept a path - dragging to the Terminal or TextEdit in plain text mode will drop the path as text in the window or document. However, this does not work with all destinations - copying to a rich-text TextEdit document, for example, copies a link to the folder and not the path.

There are some third-party apps, some free, some paid, that add this functionality. You can also create a service with Automator (or AppleScript) to do it, but a simple and free method that I like, especially if you like to use the terminal anyway, is to invoke DTerm on the Finder window and run:

pwd | pbcopy

That will copy the current path to the Mac OS X clipboard.

Tags:

Macos

Finder