Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 1.83 / 5
  You rated: 4 / 5 (77 votes cast)
 
[146,365 views]  

10.4: A simple way to copy the path to a file or folder | 47 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 whoever 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 Oct 19, '07 07:46:02AM

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 Oct 19, '07 07:58:59AM
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 Oct 19, '07 10:08:55AM
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 Oct 21, '07 08:45:30AM
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 Oct 19, '07 08:31:16AM

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: Akimbo on May 11, '13 04:19:57PM

OK, that was helpful -- thank you.



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: chrononaut on Oct 19, '07 09:20:48AM

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 Oct 19, '07 09:29:11AM
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 Oct 19, '07 12:10:04PM

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 Oct 19, '07 03:31:21PM

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 Oct 19, '07 01:33:44PM

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 Feb 12, '09 11:25:56AM

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 Oct 19, '07 05:07:30PM

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 Oct 19, '07 07:20:49PM

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 Feb 12, '09 11:37:07AM

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 Oct 20, '07 03:20:29AM

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 Feb 12, '09 11:38:45AM

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 Oct 20, '07 02:54:36PM

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 Oct 22, '07 07:41:31AM

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 Feb 12, '09 11:31:32AM

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: Sam Rohn on Oct 21, '07 12:20:40AM
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 Oct 22, '07 10:09:56AM

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 Oct 22, '07 11:24:47PM
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 Oct 22, '07 11:26:41PM

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 Oct 22, '07 11:35:00PM
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 Oct 23, '07 06:25:54AM

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 Oct 23, '07 03:38:12PM

No problem.



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: jhaslam on Jan 04, '08 03:24:34PM

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 Mar 21, '08 05:51:09AM

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 Feb 12, '09 11:47:36AM
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 Apr 21, '09 09:52:37PM

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 Apr 21, '09 09:55:42PM

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 Apr 29, '09 03:42:34PM

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 Sep 01, '09 05:40:30PM

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 Sep 04, '09 06:24:24PM

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 Sep 28, '09 05:56:38PM

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 Sep 04, '09 06:31:28PM

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 Sep 08, '09 02:34:07AM

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 | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: mangoguru on Jun 01, '10 12:13:34AM

I am impressed with this forum. So many ways of doing the same thing? Great! I found the solution! Thanks guys!



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: Anonymous on Oct 23, '10 04:24:41PM

Getting the filepath from Terminal (by dragging the appropriate file/folder into a terminal window) is not always ideal.

Mac OS converts space characters in a file or folder name to "\ " when they appear in the filepath in a Terminal window.

For example, I have a folder called "Gluten Intolerance", located in a folder called "Research", with this located in my home folder "joe", so the filepath comes out as:

/Users/joe/Research/Gluten\ Intolerance

This means that when I select the "Go to Folder..." command (in the Finder's Go menu), and paste in this filepath as it is, Finder says "Folder can't be found".

What you have to do is delete all "\" characters in the filepath, and then "Go to Folder..." will find the file or folder. You only this problem if one or more of your folder or file names contains a space.



[ Reply to This | # ]
Just drag the file into Safari's window
Authored by: jamusreynolds on Oct 28, '10 08:51:44AM

Then you can copy the URL. Only for files obviously.



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: dcover on Jun 02, '11 10:51:34AM

Having recently switched to OSX, I honestly don't understand what's so "smart" about its interface design, starting with the file path issue. Win users can move "lightening fast" by using file paths to save and find items vs. guessing and clicking into RSS oblivion.

The other blaring OMFG how could you not have this in the 21st century thing is the file cut command. Some RSS journal should really do an article on this. To simply move a file you have to copy, find the new location, paste, go back to the old location, move to trash (note you can't even use the "delete button"). Seriously, I'm beginning to think OSX interface was designed by people with bionic hands, and for the rest of us, we're waiting on peanuts, bananas, and surgery bills.

At this point, I'd say that my general productivity on a Mac due to issues like this is 30% less than on Win, and that's not even factoring all the special apps I need to torch my system with to get it to do the equivalent of stupid pet tricks on WIndows. Can somebody wake Steve Jobs up and tell him the 90s are over?

Now to update my system ... I wonder how many days that will cost me.



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: everkleer80 on Jun 03, '11 11:46:29AM

The thing you have to realize when switching to OSX is that you can't do everything exactly the same as you do in Windows; for example in Windows I save everything in a complicated directory structure since the search features kind of suck (at least in XP), but on the Mac I save most of my work under my Documents folder and use Spotlight to open everything. This is kind of an over-generalization, but hopefully you'll see my point. What is 'smart' about OSX is that you don't really have to worry about the complexities of the OS/file system - this makes it 'smart' for the average user, but I agree that there are some aspects of Windows that may be more appealing to the power user.

Anyway, in response to some of the things you are trying to do, you can enter and jump to a particular path in both the Finder and in Open/Save dialogs by pressing CMD-Shift-G (in Finder this is a shortcut for Go > Go to Folder...) Also, the shortcut to delete a file is CMD-Delete (note that the Delete key is the one that's equivalent to backspace in Windows.) It is a shame that you can't Cut & Paste files, but there are third party tools that add this functionality... and drag & drop really isn't all that bad once you get used to it.

Now remember, you're probably getting back that 30% productivity loss by not having antivirus S/W slowing down your computer! =)



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: junge on Oct 04, '11 04:54:55AM
Now it's Mac OS X 10.7 but I guess this is still relevant. What I do is I use FTP client Transmit from Panic. This may not be a practical solution to everyone but since I have it running all the time it's really easy and practical for me: Browse to the desired file or folder, local or remote, in the Transmit window, and CTRL-click to choose 'Copy URL' or 'Copy Path'. Copy URL will copy something like this to your clipboard:
file://localhost/Users/michael/Pictures/picture1.jpg
and Copy Path something like this:
/Volumes/Macintosh HD/Users/michael/Desktop/Pictures/picture1.jpg


[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: NatCk on Nov 21, '11 11:06:25PM
Bumping this thread since I couldn't find another post on this and had to piece it together myself. To get a clickable file url for any file or folder with just applescript, you can use the following code. Basically, it changes the text delimiter for filename spaces from " " to "%20". Then it prepends the POSIX location with the "file://" and copies the result to the clipboard.

on ReplaceText(theString, fString, rString)
	set current_Delimiters to text item delimiters of AppleScript
	set AppleScript's text item delimiters to fString
	set sList to every text item of theString
	set AppleScript's text item delimiters to rString
	set newString to sList as string
	set AppleScript's text item delimiters to current_Delimiters
	return newString
end ReplaceText

tell application "Finder"
	set thisFile to selection as alias
	set FilePath to "file://" & POSIX path of thisFile
	set FileURL to ReplaceText(FilePath as string, " ", "%20") of me
	set the clipboard to FileURL
end tell


[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: rd299792458 on Dec 10, '11 11:13:29AM

On Lion:

Create a script/app using Automator

Open Automator
Workflow
Select Files & Folders
Drag Get Selected Finder Items 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" | pbcopy

Save
File Format: Application

Open finder and select the Application - Then hit command+T to add it to your sidebar. Any time you want to copy the path of a selected item in finder just click the application on the sidebar.



[ Reply to This | # ]
10.4: A simple way to copy the path to a file or folder
Authored by: joenico on Dec 16, '11 09:41:01AM

In Lion you can copy the path from the Get Info (Command-I) window. Maybe this is new?



[ Reply to This | # ]