Copy Path as URL from network location

feature-request

#1

When using this option on a file on a network drive, I get a path with the file:// prefix.
I’d expect to get the server path, so I can share this URL with other users.

For example:
Now I am getting file:///Volumes/Bla/Foo/File.txt
I would expect to get smb://serverurl/Bla/Foo/File.txt, which is the path I see when I right-click and select Get Info on the file

TotalFinder 1.9.3
macOS Sierra


#2

Hi Mark,

One other user requested this functionality. The problem is how to determine serverurl from a filesystem path. At the time I didn’t know how to do that, so I proposed following functionality. It is implemented in TotalFinder, so you might give it a try. Or please propose some similar scheme how TotalFinder should determine translation from filesystem paths to share-able urls.

// Adding a new option in that context menu is simple. The problem is how
// to determine UNC path server and volume name from Mac. I think we
// should define some convention for this.
//
// Here is my proposal:
// UNC path will be constructed as follows \\server\volume\path
// let $file be absolute selected file path e.g /Volumes/myshare/some/dir/file.txt
// option to copy UNC path will be available only if $file begins with /Volumes/
// "path" is $file without first two folders, => /some/dir/file.txt
// "volume" is second folder in $file => myshare
// "server" is empty by default =>
//
// Additionally I will walk down from $file visiting every parent folder.
// If I find file named .unc-hint I will stop and read it as a config
// file. Config file may override "volume" and "server":
// .unc-hint is a text file, with up to two lines, the first is server
// name, the second is volume name.
//
// This would enable you to put .unc-hint file anywhere on your shared
// samba volumes (ideally into volume's root) to define server name.

#3

How about this code:

NSError *error=nil; //Error
NSURL *volumePath=nil; //result of UNC network mounting path

NSString* testPath =@"/Volumes/Bla/Foo/File.txt"; //File path to test
NSURL *testUrl = [NSURL fileURLWithPath:testPath]; //Create a NSURL from file path
[testUrl getResourceValue:&volumePath forKey:NSURLVolumeURLForRemountingKey error:&error]; //Get real UNC network mounted path i.e. smb://....
if(volumePath != nil)
	return [NSString stringWithFormat:@"%@://%@%@", volumePath.scheme, volumePath.host, [testUrl.path substringFromIndex:[@"/Volumes" length]]];
else
	return testUrl;

#4

This looks good. Thanks! I will implement it in the next TF version.


#5

I have implemented this in TF 1.10.0:
https://totalfinder.binaryage.com/beta-changes#1.10.0

In the end had to use slightly more complex code because network mount points don’t necessary have to be in /Volumes only. But thanks for the idea.


#6

Thanks for the implementation.

Do note that the path I receive from your code includes my username as a prefix (smb://username@server/bla)
My sample code has intentionally removed it since when sharing URLs, my username should not be included


#7

Interesting. Yes, I blindly used what system reported as mount volume url. This might be just your case that user is not important with your smb shares (which are probably public) but might be important in some other cases (e.g. with afp shares). So I’m reluctant to massage the url in any way.

I’m going to implement stripping of the user name, hidden behind a plist tweak. So you can enable it for yourself.


#8

TotalFinder 1.10.1 has added two plist tweaks.

In Terminal.app you can do:

defaults write com.binaryage.totalfinder TotalFinderStripUserFromPathURLs -bool yes
defaults write com.binaryage.totalfinder TotalFinderStripPasswordFromPathURLs -bool yes

To remove the tweak:

defaults delete com.binaryage.totalfinder TotalFinderStripUserFromPathURLs
defaults delete com.binaryage.totalfinder TotalFinderStripPasswordFromPathURLs

Finder+TotalFinder restart is needed.


#9

Can confirm it is working now. Thank you very much!