Copy file link to clipboard

I’m trying to make an automator file/folder service that will copy the URL link of a selected file or folder to my clipboard. The purpose of this is so that I can ctl+click on a file/folder and chose this service and then be able to IM the link to a fellow co-worker.

I did try pathsnagger (http://www.bergenstreetsoftware.com/pathsnagger/) but it returns a path like this:

file://localhost/xserve/Documents/01.txt

This will work for myself but doesn’t link properly when I send it to a colleague. If I use something like this:

file:///xserve/Documents/01.txt

it’ll link directly to the file.

Is this possible? Any help is greatly appreciated.

-thanks

Here is where I’m at so far:

  1. Created an Automator Service that “receives selected files or folders” in Finder

  2. Added “Run AppleScript” action with the following script:

on run {input, parameters}

(get input)

return input

end run

  1. Added “Copy to Clipboard” action

This returns the path as an alias i.e. Macintosh HD:Users:foxbot:Desktop:file.txt

I tried “get URL of input” but get an error. Not sure where I’m going wrong.

-Thanks again

Okay, I’ve made it a little further (I hope)

My Applescript is now:

on run {input, parameters}
	
	set newPath to (the POSIX path of input)
	
	return newPath
end run

This returns a POSIX path such as:

/xserve/Documents/01.txt

I need it to be:
file:///xserve/Documents/01.txt

How would I add the “file://” to the result. Also I would need to replace any spaces with “%20”

i.e.
file:///xserve/Work%20Documents/Main%20Project.txt

Thanks for the help

Think I’ve figured it out. Here’s what I came up with in case anyone is interested.

I found the Find and Replace script here:
http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/



(* this changes the Applescript path to a POSIX path *)
on run {input, parameters}
	
	set newPath to (the POSIX path of input)
	get replaceSpaces(" ", "%20", newPath)
	
end run

(* this replaces all spaces with "%20" and adds "file://" prefix *)
on replaceSpaces(find, replace, subject)
	set prevTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to find
	set subject to text items of subject
	
	set text item delimiters of AppleScript to replace
	set subject to "" & subject
	set text item delimiters of AppleScript to prevTIDs
	
	set filePrefix to "file://"
	
	return filePrefix & subject
	
end replaceSpaces