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