Thanks to the commenters for pointing out the much easier way to do this: Select an item in Finder, then press Command-Option-C. All done. Leaving the hint here as an example of a Rube Goldberg machine.
In two recent geeky tips, I showed how you can open a Terminal window in the directory of the selected Finder item, and how you can view Unix man pages in Preview. To finish the trifecta of geekiness, today's tip lets you quickly place the Unix-style path to the selected Finder item on the clipboard. (It's actually a simplified version of the 'open this in Terminal' tip.)
The AppleScript that accomplishes this is quite simple:
tell application "Finder"
set sel to the selection as text
set the clipboard to POSIX path of sel
If you run that in Script Editor, you'll see that your clipboard contains the path to whatever you had selected in Finder. But running the AppleScript in ScriptEditor isn't a great timesaver. Instead, put it into whatever tool you have that can run AppleScripts via hot key or menu bar entry or whatever.
In my case, I put it into a super-simple Keyboard Maestro macro. I've set it up to show in the Keyboard Maestro menu bar when Finder is active:
There are countless tools that can run AppleScripts in various ways, including our own Butler, LaunchBar if you save the script first, etc.
At least in OS X 10.12, if your Right Click (Control + Click) and then press the Option key you get the option to Copy "Filename" as Pathname. This places the POSIX path on the Clipboard
Handy tip, thanks—I wasn't aware. (Though it still requires the mouse; I use the keyboard to activate the Keyboard Maestro status menu.)
The Finder has this built in with Command-Option-C.
Wow…never noticed that one before! A big "never mind" to this tip, then!
Comments are closed.