Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

10.4: A simple way to copy the path to a file or folder System 10.4
Here is a very quick method to find the path of a file or folder. Press Command-Option-Space to open an empty Spotlight Results window. Drag the file or folder whose path you'd like to copy to the Search box in the Spotlight Results window. Copy the resulting path. That's it.

[robg adds: Works as described!]
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[33,409 views]  

10.4: A simple way to copy the path to a file or folder | 37 comments | Create New Account
Click here to return to the '10.4: A simple way to copy the path to a file or folder' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
10.4: A simple way to copy the path to a file or folder
Authored by: Helge33 on Fri, Oct 19 2007 at 7:46AM PDT
Sorry dont get what is "simple" here. Just like 20 years ago press Apple-Key while pointing at the Finder window name and you got the path.... works in OS9 too ;-)




[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: camarena on Fri, Oct 19 2007 at 7:58AM PDT
I created this applescript and saved it in my ~/Library/Scripts folder so I can access it from the Scripts Menu

tell application "Finder"
	set sel to the selection as text
	set the clipboard to POSIX path of sel
end tell


[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: ctierney on Fri, Oct 19 2007 at 10:08AM PDT
Hello, Here's another applescript variation in the form of a droplet:

(*
I use this script to show people where to find files on our LAN. 
Just drop a few files/folders onto this droplet and their pathes will be copied and put on the clipboard.
--CBT
*)

on open these_items
	set myItems to itemSort(these_items) -- v1.0.5 ASCIIsort failed on older versions of applescript. -- CBT; 10/5/99
	
	set path_str to "" as string
	
	repeat with i from 1 to the count of myItems
		set this_item to item i of myItems
		set posix_path to POSIX path of this_item
		
		-- For now I'm stripping the preceding '/Volumes' string for external 
		-- drives so I don't clutter my build logs.
		set shortened_path to do shell script "
			echo \"" & posix_path & "\" | sed 's|/Volumes||'
		"
		set path_str to path_str & shortened_path & return
		--set path_str to path_str & posix_path & return
	end repeat
	
	-- Copy plain text to the clipboard.
	set the clipboard to «class ktxt» of ((the path_str as text) as record)
end open

on itemSort(my_list)
	set the index_list to {}
	set the sorted_list to {}
	repeat (the number of items in my_list) times
		set the low_item to ""
		repeat with i from 1 to (number of items in my_list)
			if i is not in the index_list then
				set this_item to item i of my_list
				if the low_item as text is "" then
					set the low_item to this_item
					set the low_item_index to i
				else if this_item as text comes before the low_item as text then
					set the low_item to this_item
					set the low_item_index to i
				end if
			end if
		end repeat
		set the end of sorted_list to the low_item
		set the end of the index_list to the low_item_index
	end repeat
	return the sorted_list
end itemSort
-- Cole

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: regulus on Sun, Oct 21 2007 at 8:45AM PDT
Here's my applescript. It automatically paste's the path wherever your cursor is when you run the script. Note: I don't use the posix path so you'll have to add that yourself if you want the posix path.
tell application "Finder" to set selected_item to (item 1 of (get selection)) as Unicode text
set the clipboard to selected_item
tell application (getFrontApp()) to activate
tell application "System Events" to keystroke "v" using command down


on getFrontApp()
	set frontApp to displayed name of (info for (path to frontmost application))
	set script_name to displayed name of (info for (path to me))
	if frontApp is script_name then
		tell application "System Events" to set visible of process script_name to false
		set frontApp to displayed name of (info for (path to frontmost application))
	end if
	return frontApp
end getFrontApp


[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: erikzred on Fri, Oct 19 2007 at 8:31AM PDT
Pretty much the same as drag and drop a file or folder to the terminal window -- but this hint does save having to select the path before copying it to the clipboard.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: chrononaut on Fri, Oct 19 2007 at 9:20AM PDT
also works with Google Desktop search (which i prefer)

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: dev_sleidy on Fri, Oct 19 2007 at 9:29AM PDT
Download and install 'PathSnagger ' ('<http://www.freemacware.com/pathsnagger>;').

To use:

Right ('<control>') click on a file or folder, and select 'Snag Path HFS' or 'Snag Path Unix'.

[ Reply to This | # ]
Use Automator
Authored by: allanmarcus on Fri, Oct 19 2007 at 12:10PM PDT
oly cow, there's a very easy way to do this in automator!

Open Automator
Select Finder
Drag Get Selected Finder Items to the workflow (to position 1)
Select Automator
Drag Run Shell Script to the workflow (to position 2)
Change pass input to as arguments
Change
echo "$f"
to
echo "'$f'"
Select System
Drag Copy to Clipboard to the workflow (to position3)
Select File: Save as plug-in
Enter a name like Copy File Path
Press save.

Go to the finder and right click on a file (or a bunch of files). Select Automator: Copy File Path

Open a text editor and paste. You're done.

[ Reply to This | # ]
Use Automator
Authored by: ddauerbach on Fri, Oct 19 2007 at 3:31PM PDT
And the very nice program PathFinder offers this built in.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: barrysharp on Fri, Oct 19 2007 at 1:33PM PDT
Leopard Finder provides this by setting Finder pref.

---
Regards... Barry Sharp

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: clh on Thu, Feb 12 2009 at 11:25AM PST
What Finder pref? I don't see anything remotely like that in any of the four tabs of Finder Preferences.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: LeeH on Fri, Oct 19 2007 at 5:07PM PDT
Works just as well and the same way as the original hing by clicking on the file you want the path for, then command-space and drag the file to the Spotlight bar, select all via command-A and copy as usual

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: barrysharp on Fri, Oct 19 2007 at 7:20PM PDT
In Leo 10.5 simply use Finder's View->Show Path Bar selection.

---
Regards... Barry Sharp

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: clh on Thu, Feb 12 2009 at 11:37AM PST
That shows it, to be sure. As far as I can tell, though, it doesn't copy to the system clipboard an ASCII string containing the full Unix path to the selected file or folder. That's what we're looking for.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: robogobo on Sat, Oct 20 2007 at 3:20AM PDT
Or do a get info

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: clh on Thu, Feb 12 2009 at 11:38AM PST
It's not copyable in the Get Info panel!

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: rpitcairn on Sat, Oct 20 2007 at 2:54PM PDT
option-command-space does nothing on my iMac.
I opened a spotlight window by using command-F2 and an empty window opened. Dragged some files in to the window, all rejected and no path shows up.

[ Reply to This | # ]
You're not very good at following instructions, are you
Authored by: Lectrick on Mon, Oct 22 2007 at 7:41AM PDT
The hint says explicitly to "Drag ... to the Search box in the Spotlight Results window". The search box is the little box in the upper right. If you just drag it into the main part of the window, no, that wouldn't work. It has to be dragged to the "Search box".

I personally prefer the 4 line Applescript someone else posted. This method, while working, is kind of kludgey.

---
In /dev/null, no one can hear you scream

[ Reply to This | # ]
You're not very good at following instructions, are you
Authored by: clh on Thu, Feb 12 2009 at 11:31AM PST
And yet, even dragging it to the aforementioned Search Box doesn't work. For one thing, the box gives no visible evidence that it's, well, excited? about having the pointer tip of the mouse dragging the folder hovering over it. And you drop... and nothing happens.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: sjr on Sun, Oct 21 2007 at 12:20AM PDT
Marc Liyanage provides a simple applescript app to open a new terminal window at the current finder location here -

http://www.entropy.ch/software/applescript/

---
Sam Rohn - New York City Location Scout - http://www.nylocations.com/

[ Reply to This | # ]

10.4: A simple way to copy the path to a file or folder
Authored by: bvdecicco on Mon, Oct 22 2007 at 10:09AM PDT
How about taking this a step further.

I need to copy the path of a selected file, then change the prefix of the path to something else and then copy the file to the new location. My example is 2 identical servers, one TEST and one PROD.

/Volumes/E-TEST$/KaleidaScope2006/wwwroot/index.asp
/Volumes/E$/KaleidaScope2006/wwwroot/index.asp

They only differ in the share name. Any thoughts? I've tried poking aorund the applescript/automator sites but have not found anything close enought to modify.

Thanks.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: regulus on Mon, Oct 22 2007 at 11:24PM PDT
That's a very simple task. You use applescript's text item delimiters. Using your example, if you want to change /Volumes/E-TEST$/KaleidaScope2006/wwwroot/index.asp to /Volumes/E$/KaleidaScope2006/wwwroot/index.asp, then you want to replace /Volumes/E-TEST$ with /Volumes/E$. Here's a simple search/replace routine for you. And if you want to get the selected items path see my post above.
set myString to "/Volumes/E-TEST$/KaleidaScope2006/wwwroot/index.asp"
set search_string to "/Volumes/E-TEST$"
set replacement_string to "/Volumes/E$"

my findReplace(myString, search_string, replacement_string)



(*============ SUBROUTINE ==============*)
on findReplace(theString, search_string, replacement_string)
	repeat
		if theString contains search_string then
			set AppleScript's text item delimiters to search_string
			set the text_item_list to text items of theString
			set AppleScript's text item delimiters to replacement_string
			set the theString to every item in text_item_list as Unicode text
			set AppleScript's text item delimiters to ""
		else
			exit repeat
		end if
	end repeat
	return theString
end findReplace


[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: regulus on Mon, Oct 22 2007 at 11:26PM PDT
Oops, take out the repeat/end repeat statements from the subroutine... they're not needed.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: regulus on Mon, Oct 22 2007 at 11:35PM PDT
And if you want to get a whole applescript together, the folks over at the MacScripter forums are always willing to help... http://bbs.applescript.net/viewforum.php?id=2

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: bvdecicco on Tue, Oct 23 2007 at 6:25AM PDT
Thanks so much for the help. This will be such a great little script to have available once I get it all together.

Thank you, thank you!

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: regulus on Tue, Oct 23 2007 at 3:38PM PDT
No problem.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: jhaslam on Fri, Jan 4 2008 at 3:24PM PST
Don't know if this works in 10.4 but it seems to work in 10.5:

1. Click on the file or folder you want the path for
2. Click on 'Finder' in the menu bar
3. 'Services'
4. 'TextEdit'
5. 'New Window containing Selection'

A TextEdit window opens with the text (hyperlink) of the path, e.g. /Users/Jim/Music/file.mp3

Quite quick and easy!

---
2.4GHz 24" Alu iMac (3gb RAM)

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: PizzaCake on Fri, Mar 21 2008 at 5:51AM PDT
great tip, plus the textedit link is in the file:// format

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: clh on Thu, Feb 12 2009 at 11:47AM PST
This is embarrassing! I certainly can't get the originally-posted method to work (Spotlight / Drag&Drop in Search Box), and many of the other suggestions seem to miss the point that what's desired (at least by me) is to place into the system clipboard a Unix-style path that can then be pasted into a plain-text document!

What is most amazing is that Get Info, while it does display the full path of the file or folder in question, does not let you select it for command-C copying. Plenty of other read-only text is copyable; why not this?

Phaw.

[ Reply to This | # ]

10.4: A simple way to copy the path to a file or folder
Authored by: iangr on Tue, Apr 21 2009 at 9:52PM PDT
The best solution was overcrowded by all of the other answers!

Simply "drag and drop a file or folder to the terminal window"!

There's your selectable, copyable file path!

Of course, you are correct, that one should be able copy the file path from a file's info window!

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: iangr on Tue, Apr 21 2009 at 9:55PM PDT
Oh, also, the Cmd-Opt-Space doesn't open a Spotlight window anyway, on systems with more than one language. I use Namely to quickly launch Terminal, and it's easy to copy and paste from there.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: aaronsk on Wed, Apr 29 2009 at 3:42PM PDT
1) Select the folder or file
2) From the main menu, select Finder > Services > Summarize

Boom. A directory path you can copy.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: jetak on Tue, Sep 1 2009 at 5:40PM PDT
In Snow Leopard the Automator plugin support has been changed so allanmarcus Automator script will no longer work, but it is easy to fix.

Snow Leopard has done away with the contextual menu plugin support and now calls them 'Services'. There is no longer a Save As -> Plug-in option in Automator. Now when you open Automator, choose the 'Service' template, then follow these instructions:

--------------------------Begin Script---------------------------
At the very top change the drop down lists so the look like:
Service receives selected 'files or folders' in 'Finder.app'

Select Finder & Folders
Drag Get Selected Files and Folders to the workflow (to position 1)

Select Utilities
Drag Run Shell Script to the workflow (to position 2)

Change pass input to as arguments
Change
echo "$f"
to
echo "'$f'"

Select Utilities
Drag Copy to Clipboard to the workflow (to position3)

Save
Call it something like 'Copy Path'
--------------------------End Script---------------------------

You now should now have a new item called 'Copy Path' in your Finder contextual menu (the right click menu).

I am having an issue when copying the directory path for a file. When I paste the results, it pastes two lines of the identical path. It is the correct path just copied twice. It only seems to do this to files and not folders and when I run the script in Automator it seems to work fine.

Other than that little issue this method seems to work great.

I also tried making this same Automator script into an app and then adding it to Services-> Services Preferences-> Application Shortcuts and then giving it a shortcut like opt-cmd-v but this did not work, though I have not really tried that hard.

[ Reply to This | # ]
Snow Leopard: A simple way to copy the path to a file or folder
Authored by: granolamike on Fri, Sep 4 2009 at 6:24PM PDT
I get the same duplicate result when I use Copy Path in the contextual menu (created using Automator) with Snow Leopard.

Note in Snow Leopard you can just copy the path out of the Get Info box too.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: spamathon on Mon, Sep 28 2009 at 5:56PM PDT
You're getting the duplicate folder list because you've forgotten to take out the first action (Get Selected Finder Items). You only need it to test the workflow in Automator - once you've finished testing, remove the first item so it just looks like:

(receives "files or folders" in "Finder.app")
V
Run Shell Script (add the ' ' so you get slashes instead of colons)
V
Copy to Clipboard

Done!

[ Reply to This | # ]
Snow Leopard: A simple way to copy the path to a file or folder
Authored by: granolamike on Fri, Sep 4 2009 at 6:31PM PDT
You can copy the path right out of the Get Info window in Snow Leopard.

[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: socheesome on Tue, Sep 8 2009 at 2:34AM PDT
Hello Jetack and thanks.
A simple question, do you know how can I adapt your script to convert the path to a "windows" format and then copy it to the clipboard ?

I image the things to do are:
- store the path inside a variable
- replace all / to \
- remove "file://" anche change it with a specific prefix
- change spaces ?

Thankyou in advance for the help, Cheers

[ Reply to This | # ]