10.6: Create a Service to copy a file path URL to the clipboard

Dec 04, '09 07:30:03AM

Contributed by: BiL Castine

Snow Leopard only hintThis simple Automator Service will copy the path of a Finder item to the clipboard as a file:// URL; this is very helpful in my environment, where I need to send a shared file's location to someone, rather than emailing around copies of a file.

In Automator, create a new Service and set it to receive selected files or folders in the Finder. Next add the Copy to Clipboard action. For the final step, drag in the Run a Shell Script action, and paste in the following code (all on one line, replacing any existing code):

sed -e 's/:/\//g' -e 's/\ /%20/g' -e 's/^/file:\/\//g' | pbcopy

This transforms the Mac-style colon-delimited path into a POSIX path, and prepends file://, so the path becomes a clickable link when pasted into an email.

[robg adds: This worked as described in my testing.]

Comments (23)

Mac OS X Hints