Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Put a file's path on the clipboard via AppleScript System
If you need a quick way to get the full path to a file or folder, save the following Applescript as an application:
on open {dropped_item}
  tell application "Finder" to set the clipboard to the 
   dropped_item as text
end open
Copy and paste the text into Script Editor, then choose File » Save As, and set the File Format pop-up to application. Then whenever you need to get the path to an item, simply drag that item onto your script's application icon, and the path to the dropped item will be placed on the clipboard.
    •    
  • Currently 3.33 / 5
  You rated: 2 / 5 (6 votes cast)
 
[40,077 views]  

Put a file's path on the clipboard via AppleScript | 11 comments | Create New Account
Click here to return to the 'Put a file's path on the clipboard via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Put a file's path on the clipboard via AppleScript
Authored by: LeeH on Apr 18, '07 07:44:50AM
You might also want to try the free contactual menu plug-in PathSnagger. It is available at MacUpdate (http://www.macupdate.com/info.php/id/13623). It also puts the path to the clipboard.

[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: hsinha on Apr 18, '07 07:45:01AM
Or one can use this useful contextual menu item "PathSnagger" from
<http://www.bergenstreetsoftware.com>;

which can copy Unix or HFS style paths to clipboard which can be set up using prefpane.


[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: mattybinks on Apr 18, '07 09:52:07AM

This version is a little shorter. I use it as a run-only app in my Scripts menu. Just click on an item in the Finder so it's highlighted (you don't have to open it) and then select this script from the Scripts menu.

on open (theFile)
set the clipboard to theFile as text
end open



[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: lmn on Apr 18, '07 10:15:47AM
You can also make your own Automator plug-in (contextual menu item) that runs a script which copies the Unix paths of all items selected in the Finder. The paths are quoted for (mostly) trouble-free pasting into Terminal. For one item, this should work:

tell application "Finder" to set the clipboard to quoted form of (POSIX path of (the selection as alias))
and for multiple selected items, this script puts each item's path on the clipboard, on separate lines:

set theSel to (selection of application "Finder")
set pathList to {}
repeat with anItem in theSel
set the end of pathList to quoted form of (POSIX path of (anItem as alias))
end repeat
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "
"
set the clipboard to pathList as string
set AppleScript's text item delimiters to savedDelimiters


[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: astrosmash on Apr 18, '07 10:16:04AM

Nit pick: you'll want to save scripts as an 'Application Bundle', not as an Application. 'Application' scripts aren't Universal and run under Rosetta on Intel Macs.



[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: pvantees on Apr 18, '07 12:22:10PM
I've been using this one for some time now: http://www.pure-mac.com/cmm.html#filepathtoclip
It's a contextual menu plugin. Rightclick ... go!

[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: pmoreira on Apr 18, '07 02:24:46PM

I'm a big fan of Quicksilver, and as I was trying this hint I realized Quicksilver already allows you to do this, it's called Get File Path, then do Copy To Clipboard and voila! :)

Also, if you have that option on in Quicksilver, select the file you want on the finder, and Cmd-Esc pops up Quicksilver with that file selected.



[ Reply to This | # ]
Method 99: Using On My Command
Authored by: klktrk on Apr 18, '07 04:25:52PM

If you already are using the astonishingly customizable toolbox for contextual menu plugins called On My Command, you can either a) download the plugin for it that I made called "show path", or use the following code and make a new one in OMCEdit:
Activation Mode: File
Location: First Level
Execution Mode: Shell Script with Output window
Escape special characters: None

echo __OBJ_PATH__ | pbcopy;
echo __OBJ_PATH__;

**
This will put the path of the selected Finder object on the clipboard as well as display a simple window displaying the path.



[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: jmck on Apr 19, '07 07:43:07AM
I wrote this droplet to make sure what I get is a Unix-style path that can be used with Services>Finder>Reveal, et cetera

on open theFile
	set thePath to POSIX path of theFile
	set the clipboard to thePath as text
end open
For non-Cocoa email apps, Acrobat, etc, this companion script will take the place of Services>Finder>Reveal : take a POSIX path off of the clipboard and reveal it in the Finder.

	set posixPath to the clipboard
	set pf to POSIX file posixPath
	set a to pf as alias
	tell application "Finder"
		activate
		reveal a
	end tell

---
--jmck

[ Reply to This | # ]

Put a file's path on the clipboard via AppleScript
Authored by: Occam on Apr 19, '07 09:44:56AM

The following script saved as an application will put an active link into clipboard which if pasted into say, TextEdit' will create a link in TextEdit which will open the linked file.

on open {dropped_item}
tell application "Finder" to set the clipboard to "fttp:///" & (POSIX path of (the selection as alias))
end open



[ Reply to This | # ]
Put a file's path on the clipboard via AppleScript
Authored by: Carl Stawicki on Apr 20, '07 07:41:03AM
I made this script to copy the path of an item selected in the Finder to the clipboard. It it useful for adding the item's path to a script or email. It gives the choice of getting the alias or posix paths. To use it, select the item in the Finder and run the script. Select which path you want copied to the clipboard. It is especially handy to place the script into your window toolbar.
tell application "Finder"
	activate
	set thisFile to selection as alias
	set theChoice to button returned of (display dialog "Alias Path or Posix Path for " & return & return & ((name of thisFile) as text) & "?" buttons {"Posix", "Alias"} default button 2 with icon note)
	if theChoice = "Posix" then
		set the clipboard to (POSIX path of thisFile) as text
	else
		set the clipboard to "alias \"" & (thisFile as text) & "\"" as text
	end if
	beep
end tell
Carl.

[ Reply to This | # ]