Posted on 25th September 2015 by David Acland

Connecting to a file server from Mac OS X – Part 2

connect to server

Building on my previous blog post, this article will describe some of the methods you can use to provide network drive shortcuts for your users.  Specifically, we will include:

  1. Favorites in the Connect to server box
  2. Manually and programatically adding to the Finder sidebar
  3. Shortcuts on the desktop
  4. Manually and programatically adding to the Dock

Although I’ll be focusing on the technical ways to get these shortcuts deployed to your users, it’s always worth mentioning that this is something most people (and I mean your users!) would be able to handle themselves.  

I’m a big advocate of user training and allowing them to become more self sufficient.  If they know how to add a network drive to the Dock and need a new one, they can do it themselves straight away.  If you’ve always provided the Dock icons for them, they will have to ask you to add more items, FOREVER.  I’ll get off my soap box now and get back to the technical side, but it’s just something I wanted to get off my chest.

Connect to server box

The first way to provide server shortcuts to your users is to utilise the built-in Connect to server “favorites” window.  In the GUI, with the dialogue box open, you simply type an address and then click the + button on the right:

connect to server

If you want to get a default set of these out to multiple users, the data is stored in the com.apple.sidebarlists.plist file in the favoriteservers dictionary array.

In earlier versions of OS X you could use the user template folder to make sure the plist is in place for any new users logging in.  In the past few years this method has become less effective.  Instead, you can use a tool like mcxtoprofile.py to create a custom config profile from the favoriteservers section of the sidebar lists preference file.

The Finder Sidebar

I’m often asked to implement something and the request is followed up with “That should be easy to do, right?”.  For a lot of these settings the short answer is no.  The sidebarlists plist file is definitely one of the nastier preference files to manage, depending on the tool you use.

More recently, I’ve been making use of a fantastic python script from Matt4836 on Github.  This script lets us add and remove items from the Dock, including paths that would be unique per user.  The basic commands that add items to the sidebar (using changesidebarlists.py) are:

Adding static paths to the sidebar:

Change_Sidebar_List.py first /Volumes/MyShare

Adding variable paths like home folders to the sidebar:

Change_Sidebar_List.py first /Volumes/$USER

So if I had a user network home and a shared network drive to add to each users Finder sidebar, the script would look something like this:

#!/bin/sh

Change_Sidebar_List.py first /Volumes/MyShare

Change_Sidebar_List.py first /Volumes/$USER

exit 0

We use Casper a lot at Amsys so I would normally use the login trigger set to “Once per user” to run the script. Casper has a really nice feature called “parameter labels” so we would normally add the script to the JSS but use variables for the server and share values like this:

#!/bin/sh

Change_Sidebar_List.py first /Volumes/$4

exit 0

I’d then set the parameter labels like this:

parameter labels

Then in my policy I can slot in the variables I want:

variables

What if I don’t use Casper?

In this case I like to use Outset from Joseph Chilcote.  This is another awesome tool that lets you run scripts and install packages at boot time or at login.  it avoids you having to create a LaunchAgent for each script you want to run at login so is pretty handy.

If you’re adding an item to the Finder sidebar for each user that logs in you would add your script to /usr/local/outset/login-once.

Shortcuts on the Desktop

A desktop shortcut is a bit of an odd one that I’ve seen a few people use and there’s two ways to create them:

Using an alias:

  1. Connect to the network drive
  2. Select its icon on the desktop
  3. Press “Command + L”.  This will add a shortcut onto the desktop.

Using a webloc file:

This option will let you specify an exact share name, or just the server address to get a list of available shares.

1. Open Safari and type in the server (and optionally the share name).  I.e. afp://your.server.com/MyShare

2. Click and drag the small blue globe to the desktop

myshare

3. Rename the file to something friendly

rename the file

4. Optionally, give the file a nice icon by copying the icon from a mounted network share

mounted network share

When the shares mount, the users desktop will end up with multiple icons with the same name.  So if the alias or weblog filer is called “MyShare” and they connect to the sharepoint called “MyShare”, they will end up with this:

my share sharepoint

That being said, the shortcuts are useful for adding to the Dock if they are tucked away into a subfolder like ~/Documents.

Adding to the Dock

The last option we use for server shortcuts is the Dock.

You can do this easily in the GUI by dragging a network drive to the righthand side of the Dock.

To do this via a script, we normally use dockutil from Kyle Crawford.  This lets you add items to the Dock with commands like this:

dockutil --add '/path/to/shortcut.webloc' --label 'MyShare'

If you want the share in all user docks on that Mac, append with the —allhomes option:

dockutil --add '/path/to/shortcut.webloc' --label 'MyShare' --allhomes

If you want to add a network home folder, use a variable for the users short name, such as:

dockutil --add '/Volumes/$USER' --label $USER

Add the command to outset or a Casper login policy so it is added to the Dock for each user that logs in (note that Casper would use $3 rather than $USER as a variable for the users short name).

Disclaimer:
While the author has taken care to provide our readers with accurate information, please use your discretion before acting upon information based on the blog post. Amsys will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.