If you are working in a team that is using shared (Dropbox) folders to collaborate, it’s sometimes necessary to point team members to where they can find an individual file or folder. Instead of sending them a link that opens in a browser, I often just want to point them to a particular file they already have in the shared folder on their computer.
So in this post, I will show you a simple method of how to copy the path of any file or folder to the clipboard via Finder. I will also show you how you can use a shell script and a simple filter in Pastebot (App Store) to remove parts of the path before pasting it automatically.
In 2014, I suggested using an Automator service to share the path of a file or folder via Finder. As it turned out, the solution is much easier, and I have to thank Daniel, one of my readers for pointing that out.
As part of my job as a technology executive, I am part of a team that uses Dropbox to share files and folders. But the methods described below work with any folder and with all Cloud providers. For example, if I am working on a new product flyer that I would like a coworker to see, I just have to point them to the correct folder in Dropbox.
We store the raw Adobe InDesign files for our flyers in
- /Users/mk/Dropbox/Xiting/Team Share/Collateral/Flyers/InDesign – DinA4
So if I wanted to tell a team member to check out the latest draft, I would ask them to look for it in our team share, under Collateral –> Flyers –> InDesign – DinA4. That’s a lot of repetitive typing that I would rather avoid.
The OPTION Key to The Rescue
You may already be familiar what role the OPTION key plays in macOS. Among other things, it offers you additional or alternative menu options when you press it. That also includes the context menu in Finder.
To try it out, just open Finder and right-click on any file or folder. What you will get is a context menu that allows you to execute certain functions on the selected item, such as copying it. Pay close attention what happens to the Copy “ITEM” menu entry when you press the OPTION key. It changes to Copy “ITEM” as Pathname.
In my example right-clicking on the folder “InDesign – DinA4” reveals the option Copy “InDesign – DinA4” but when I press the OPTION key it changes to Copy “InDesign – DinA4” as Pathname.
By copying the item as Pathname, Finder copies the full path of the item to the clipboard. On my iMac that is: /Users/mk/Dropbox/Xiting/Team Share/Collateral/Flyers/InDesign – DinA4.
The only minor issue with that is, it contains path information that may be confusing for less tech-savvy users, particularly the part I marked in bold above.
- /Users/mk is likely unique to my Mac unless the recipient also has a Mac and uses “mk” as his or her username
- /Xiting is a folder I had created before I shared the folder “Team Share” and other users likely don’t have it.
In other words, other members of the shared folder may only see [PREFIX]/Dropbox/Team Share/Collateral/Flyers/InDesign – DinA4. [PREFIX] is different for everybody, based on the operating system they are using, their account name and individual folder hierarchies. So I thought it would be great if I could automatically remove the [PREFIX] before sharing the path with other users.
As you probably know, COMMAND + C is the default keyboard shortcut for the copy command in macOS. So it shouldn’t come as a surprise that Apple also provides OPTION + COMMAND + C as the default keyboard shortcut for the “copy path” command. So next time you want to copy the path of an item in Finder, don’t even bother right-clicking. Instead just press OPTION + COMMAND + C.
Pastebot to The Rescue
Tapbots Pastebot (App Store) is my favorite copy/paste and clipboard manager. Among its many useful features, it allows me to apply filters to copied items before pasting them.
One of the supported filter categories includes Shell scripts. So I wrote a simple script that would remove a predefined string from a copied path. For example, the following script will remove /Users/mk/Dropbox/Xiting/ from the copied path, leaving me with only Team Share/Collateral/Flyers/InDesign – DinA4:
Pastebot passes data to its filters via the standard input (STDIN), so I use the ‘read’ command to fetch the data on line 1. On line 2, I define what string I want to replace before doing the replacement using built-in shell commands on line 3. Line 4 writes the modified string to the standard output (STDOUT).
How To Create A New Filter In Pastebot
To create a new filter in Pastebot, open the application and select one of the filter categories on the left side of the UI. I decided to create my “Remove Dropbox Prefix” filter under General. But you can use whatever category you like. Then click on the add filter (+) button in the upper right, give your filter a name, choose the type in the drop-down field (Shell Script) and paste the above script. Of course, you need to change the path a bit to match your environment. Then click save and optionally, assign a keyboard shortcut. I chose CONTROL + OPTION + COMMAND + V as my keyboard shortcut to automatically remove the Dropbox prefix.
As a result, if I want to share a path to a given file or folder with a coworker, I select the item in Finder, press OPTION + COMMAND + C and then paste the path via CONTROL + OPTION + COMMAND + V.
How To Copy A File Or Folder Path In Finder
I understand that the examples given above may only reflect my specific use cases. For more advanced techniques, or if you don’t use Pastebot, you could also write an Automator service and process the copied path using Apple Script.
The possibilities are endless. So if you come up with a cool idea of where to take the mentioned techniques, please let me know by leaving a comment below!