Mar 27 2008

Copy Finder Path to Clipboard – Tip 1

Published by at 6:20 am under AppleScript,System,Tools/Utilities

  

I’ve written a short script that I’ve found more useful that I ever anticipated. It is nothing more than an AppleScript application that copies the current path of Finder to the clipboard. Sounds rather unassuming, however, I think you’ll be surprised how handy it is.

The AppleScript code is less than 10 lines that instruct Finder to get the path of the front most Finder window and copy the path to the clipboard.

Script Editor Click here to paste the code below into the Script Editor

try
  tell application "Finder"
    set currentPath to (POSIX path of (target of front window as alias))
    set the clipboard to currentPath
  end tell
on error
  display dialog "Unable to copy a path to the clipboard.
                      Make sure Finder is referencing a directory/folder
                      within the file system."
                      buttons {"Ok"} with icon caution with title "Error"
end try

From within Script Editor, save the code as an application and then drag/drop the application to the toolbar in Finder. The screenshot below shows the Script Editor icon in Finder (to the right of the terminal window with the green arrow), where it is now one click away.

There is a trivial amount of error handling in this short script. If you try and run this script while Finder is referencing the system (as compared to a directory/folder on the system) you’ll get the following error message.

In the next tip of this series we’ll drill down one level further and I’ll show how to copy the path of a selected folder within the current Finder window, to the clipboard.

10 responses so far

10 Responses to “Copy Finder Path to Clipboard – Tip 1”

  1. Matt Platteon 28 Mar 2008 at 6:26 am

    Wow, that was simple. Thanks for the Apple script tutorial and thanks for bridging an Apple annoyance gap that I’ve had since forever.

  2. johnon 28 Mar 2008 at 6:33 am

    No problem, Matt, glad you found it helpful. Check out Tip #2 (the next post) that supports dragging and dropping a folder onto the script/icon…

  3. PC-Bjornon 02 Oct 2008 at 7:10 am

    Great! I´ve been looking for something like this. In Windows 2000 and newer one is able to copy/paste addresses in Explorer (the Windows-equivalent to Finder). I use that all the time and having to click around in OSX is extremely annoying. Somebody should make a whole archive of useful scripts like these. :)

  4. Jenon 17 Nov 2008 at 9:06 am

    Fantastic – have recently been using the terminal window a lot (playing with MySQL & other command-line software) and this has solved a major annoyance. It was the one tiny area where I thought that Windows had won the battle for usability. I can’t imagine why Apple haven’t included this feature as standard. Thanks very much.

  5. Methon 11 Dec 2008 at 10:38 pm

    Jen, have you tried drag’n'dropping to the terminal window?

  6. Patrick Lemiexon 11 Jan 2009 at 1:21 pm

    Question:
    Great!

    How to make it so I can automatically run the script without having the “Run Script” dialog pop up.

    How do I customize the icon?

    Thanks,
    Patrick

  7. Mariaon 22 Sep 2009 at 6:04 am

    Thanks very much, this is really very useful. Especially since I have been trying to copy directory paths using my tablet and there is a delay in selecting each individual folder hierarchy. I no longer envy pc copy and paste directory.

  8. sition 19 Jan 2010 at 9:51 pm

    this is really helpful. Many thanks

  9. Guntaron 09 Oct 2010 at 7:32 am

    It’s really helpful. Thank you very much. I really appreciate it. This simple tweak can really make saving files process much more easier.

  10. Tongon 03 Dec 2011 at 1:18 pm

    That is really what I want! Thanks a lot!

    I will try to learn more about AppleScript.