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


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: 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 | # ]