Mac AppleScript Finder - How to put the path of the current Finder window on the clipboard

Mac OS X FAQ: How can I get access to the full path of the current Finder window? That is, when I’m looking at a Finder window that’s showing the contents of a directory like /Users/Al/foo/bar, how can I easily put that directory path on the clipboard so I can use it in other applications?

Solution

I couldn’t find any way to do this through the Finder, so I wrote an AppleScript script to do it for me. Here’s my script that gets the current path from the Mac Finder and displays the path in a dialog so you can copy it to the OS X clipboard:

tell application "Finder"
    set theWin to window 1
    set thePath to (POSIX path of (target of theWin as alias))
    display dialog thePath buttons {"Clipboard", "OK"} default button 2
    if the button returned of the result is "Clipboard" then
        set the clipboard to thePath
    end if
end tell

One thing to note is that the Finder should be the foreground window when you run this script. (If it isn’t, you’ll see a wheel/sprocket menu item appear in the Mac menu bar, and the Finder icon will start jumping in the Dock. Just click the Finder icon in the Dock to make this behavior stop.)

You can send the path to the OS X clipboard without the use of a dialog, but even though it’s an extra step, I like the visual feedback. (It also helps in case you forget to have the Finder as your foreground window when you run the script.)

Access via the AppleScript menu

I set up my system so I can run this script from the AppleScript menu, like this:

If you haven’t done this before, I describe how to configure this AppleScript menu in the “Related” section below.

Running the script

When I run this script, this is an example of what the resulting dialog looks like:

AppleScript to show the Mac OS X Finder path

At this point you can manually copy and paste the Finder path, or just press the Clipboard button to have the path sent to your Mac OS X clipboard.

Related

In summary, if you were looking for an AppleScript script to get the current path from the Mac OS X Finder, I hope this is helpful.

Post new comment

The content of this field is kept private and will not be shown publicly.