How to create a link, for multiple users, to a network share, which itself is on a network share?

apple.stackexchange https://apple.stackexchange.com/questions/362778

  •  30-04-2021
  •  | 
  •  

Question

Working Windows-based solution

I've got a folder on a network share which works great in Windows. It is basically an index of other available file servers. It looks something like this:

\\server1\directory
    Server2.lnk   <-(links to \\server2\files)
    Server3.lnk   <-(links to \\server3\files)
    Server4.lnk   <-(links to \\server4\files)

I'm trying to replicate this functionality in macOS, but I have run into these problems:

Attempting to use an Alias in macOS

I connected to //server2/files via Finder using Go -> Connect to Server. Once I was connected in Finder, I created an Alias using for the //server2/files folder. I then copied that Alias to the //server1/directory location. The Alias works... as long as I'm using the same computer from which I created the Alias. But if I try to use it from another mac, it fails.

The other mac doesn't even seem to recognize the file as an Alias file. It has an icon similar to a terminal icon, and when I double-click it, the mac tells me that there is no Application defined to open the file. I noticed that the original created Alias file doesn't seem to have any kind of extension, so I'm not sure how a different mac is supposed to recognize it as an Alias file.

The nice thing about a Windows .lnk file is that it seems to work reliably and consistently no matter from what machine the .lnk is accessed, whereas a mac Alias file seems to somehow depend on some configuration of the original machine where it was created.

For example, if I open the Alias file in vi, I can see amongst the garbled code that it includes at least the username used to access the Share, whereas I want each user that clicks on the Alias to access the Share using their own credentials (the mac is joined to AD and users login using their AD credentials). Again, this works seamlessly with UNC paths and .lnk files.

Attempting to use a terminal script in macOS

I tried to make a simple script that mounts the shares. So inside //server1/directory I created a file Server2.command with the following content:

mkdir /Volumes/Server2
mount_smbfs //server2/files /Volumes/Server2
cd /Volumes/Server2
open .

My problem with this solution is that I have many servers and many users using the same machine. One great thing about using the Connect to Server option in Finder is that it seems to automatically "clean up" the /Volumes directory. After ejecting a share, or after ending a session, it removes the corresponding /Volumes/Sharename folder. I don't see any way to accomplish the same behavior if I use this terminal-based solution.

Question

Can someone give me a good way to replicate the .lnk functionality I have described above?

I know the Windows links functions via UNC paths, whereas in macOS I can only access these network shares via smb or afp mounts, but since I see that the Connect to Server option pretty much functions how I need it to, I just need a way to use that same functionality, with the caveat that I need to automate it, because I'm not going to ask my Users (I have many Users using the same machine) to each create a Connect to Server Alias manually.

Was it helpful?

Solution

Found the answer. You must create an .afploc file. This is similar to an .inetloc file.

The easiest way to create a .afploc file:

  1. open Finder
  2. Go -> Connect to Server
  3. type the address in the Connect to Server window (e.g. afp://server.domain.com/
  4. highlight what you just typed (afp://server.domain.com)
  5. grab what you just highlighted and drag it to the desktop (or any folder, presumably) and release
  6. a file named server.domain.com.afploc should be created automatically on your desktop
  7. you can then copy that file anywhere and it will function to automatically start the Go -> Connect to Server process on any mac computer
  8. you can also rename the file if you want, and you can edit its contents to create other .afploc files that point to other servers or paths
  9. you can also use this same process and substitute an smb:// path. this creates an .inetloc file which works the same way

OTHER TIPS

To complement Daniel's answer, it may be worth noting that these .afploc or .inetloc files are just plain XML plist files. So you could also generate them by hand or from a script. An example file for an smb share looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>URL</key>
    <string>smb://server/share</string>
</dict>
</plist>

So if you have many such shortcuts to define, you could have a file like this:

$ cat shares.txt 
server1 share1
server2 share2
server3 other-share

And then run this to generate .inetloc files for every server-share:

cat shares.txt | while read server share; do
  cat <<'EOF' >"$server-$share.inetloc"
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
      <key>URL</key>
      <string>smb://$server/$share</string>
  </dict>
  </plist>
EOF
done

My feeling about what you want to achieve in Mac OS (or a Unix) works with a symbolic link. Finder has functionalities above OS embedded functions. I guess an alias won't work with Terminal / Shell. Symbolic links are created on the shell but also work transparent in Finder. Try out the thread Backup iPhone to external drive on Mac ... this explains symbolic links wonderfully.

Hope, this was what your are looking for!

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top