I was recently considering writing a Finder Contextual Menu plug-in that would copy the POSIX path of a file or directory into the clipboard when you right clicked on the file and choose "Copy Path".
I thought someone might have done this before, so I searched around and found this article, Writing Contextual Menu Plugins for OS X, that used that concept as it's example project and included the Xcode project source code. I updated the project for Xcode 2.4.1 and made it Universal without to much difficulty, and just thought that I would point others over to this useful piece of software. I've attached my updated project here.
I think that if you just copy an item, and then paste it into a text field it will paste in the path. Your solution is more reliable though, because just copying an item might paste (a) the item, (b) the file name, or© the full path, depending on where you paste it (like a rich text document). I’ve not figured out the rules yet.
JP
If you copy an item and paste it as text you’ll get the filename only, not the path. It’s mimicking the classic Mac behavior there.
Thanks for the plugin, Sean! I’ve been looking for something like that. I’ve always just dragged it into a Terminal window and then copied that out and pasted it elsewhere. A bit of a pain, but I’m nothing if not a sucker for the tedious solutions that just work.
Hi Sean,
Thanks for posting your modified CopyPath project.
One minor note: it seems that FSRefMakePath() will return a path with unescaped whitespaces, which means that paths that contain spaces in their names will confuse cmd-line apps when one attempts to C&P them for use in a terminal/shell session.
One option is to enclose the entire path in double-quotes before sending it to the clipboard — I’ve made a minor tweak to handleSelection() in CopyPathPlugin.c that does this. (Again, it’s a fairly trivial change and somewhat klugey but I can send it to you or post the changes here if you like)
I’m not a Mac developer, so I have no idea what to do with the attached files. Would it be possible for you to provide the plugin in a compiled format?
Ditto. I’d like to know how to implement this, as I’m not a developer. I arrived here from Google, searching for a way to send a file location to a buddy on the same network. Does it also work for sending Windows file paths? (They’re formatted differently).
My C skillz have pretty much gone AWOL over the last few years so my attempts to modify the code for my case have failed …appreciate a hand if anyones got the time. I’m wanting to trim “/private/var/automount” from anything copied that has it at the start of the path. Reason is so that copied paths can work on platforms other than mac – as mac is the only one that uses /private/var/automount.
TIA.