How can I copy the full smb:// link from a file in Finder?

I work in a Windows environment with many different shared drives. I commonly have Finder windows open to different shared drives and nested folders. I have a Service set up (that I created in Automator) that allows me to control-click and "copy full path" of a file or folder that I have selected in the Finder.

What I'm getting looks something like:

/Volumes/someFolder/someFile.docx

However, if I select that item in the Finder and do command-i, I see the full smb:// path that also includes the server name. I would like to copy this, so that it looks like:

smb://Server/someParentFolder/someFolder/someFile.docx

How can I create a service in Automator that will copy the entire smb:// network path to the selected file instead of the one that reports as being the full path?

If Automator won't copy the smb:// network path, is there another way I can create a utility that will do this?


Solution 1:

You can right click the file, and choose "Get Info" - the popup window will have a property for Server which lists the full URL path with protocol (e.g. smb://example.com/Data/file.png)

Solution 2:

Two years down the road this remains an annoying issue, and not finding a good answer to a similar question, I made an automator service that does this as part of the work needed to make an .inetloc file from the Finder.

Basically, it finds the mount point of the current share using the output of the mount command and matches it up to the 'mounted' path, then glues the two together like Iacopo mentioned above.

Here's how you could do what you want:

Pass the selected finder item to a shell script in automator (as a variable, not stdin) and use this script:

# Match the server address and share/subfolder to the mount point,
# using 'mount' command output:
FIRSTPART=$(mount | grep "$(echo $1 | cut -d '/' -f 1-3)" | sed 's/^.*@\(.*\) on.*$/\1/g')

# Glue on the rest of the path
SECONDPART=$(echo $1 | cut -d '/' -f 4-)
WHOLETHING=$FIRSTPART/$SECONDPART

# now we url encode it
# oneliner modified from http://stackoverflow.com/a/10797966
ENCODED=$(echo "$WHOLETHING" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | cut -c 3- | rev | cut -c 4- | rev)
# and we need to change the %2Fs back into /s, and add the smb://

FINAL=smb://$(echo $ENCODED | sed 's/\%2F/\//g')

echo "$FINAL"

Then you can use a "Copy to Clipboard" action after the script. Should do the trick. If anyone wants the automator service to make the corresponding .inetloc file, that can be found here.