Change Finder display name of share mounted using NetFSMountURLSync

333 Views Asked by At

I am attempting to write a command line app to connect to a share drive on another Mac. The code below connects the share but I can't seem to find a way to manipulate the host name that appears in the Shared section in the left panel of Finder. Assuming the remote computer's host name is computer, I'd like for it to show computer and not computer.local as it does using this code. It is a requirement to connect using the MDNS host name. I've tried setting the keys kNetFSServerDisplayNameKey and kNetFSDisplayNameKey but they don't seem to affect what is shown in Finder.

Code:

NSString *target = @"smb://computer.local/share";
NSString *mountPath = @"/Volumes/share";
CFStringRef servername = (CFStringRef) @"computer";

CFMutableDictionaryRef mount_options = CFDictionaryCreateMutable( NULL, 0, NULL, NULL);
CFDictionarySetValue(mount_options, kNetFSSoftMountKey, kCFBooleanTrue);
CFDictionarySetValue(mount_options, kNetFSMountAtMountDirKey, kCFBooleanTrue);
CFDictionarySetValue(mount_options, kNetFSServerDisplayNameKey, servername);
CFDictionarySetValue(mount_options, kNetFSDisplayNameKey, servername);
CFArrayRef mountpoints = NULL;

CFStringRef login = (__bridge CFStringRef) @"login";
CFStringRef pass = (__bridge CFStringRef) @"pass";

OSStatus err = NetFSMountURLSync(
                                 (__bridge CFURLRef) [NSURL URLWithString: target], // URL to mount, e.g. nfs://server/path
                                 (__bridge CFURLRef) [NSURL URLWithString: mountPath],  // Path for the mountpoint
                                 login,                                             // Auth user name (overrides URL)
                                 pass,                                             // Auth password (overrides URL)
                                 NULL,                                             // Options for session open (see below)
                                 mount_options,                                    // Options for mounting (see below)
                                 &mountpoints);                                    // Array of mountpoints
1

There are 1 best solutions below

0
Ian K On BEST ANSWER

I figured this out by checking the info on the volume after mounting it using Finder. When you mount the share through Finder, the Server field in Get Info for the volume is smb://computer._smb._tcp.local/share. Using this URL instead of smb://computer.local/share in the code above results in computer showing in the left Shared panel in finder and not computer.local.