Auto-Mount Shares

With OS X LaunchAgents

Published / Modified

  • 2015-02-24
  • /
  • 2023-09-25

Categories

Tags

Related Articles

Mounty Can

With Mounty you are in full control of your favourite file shares: setup your shares once and whenever you log into your computer your shares get mounted automagically.

Features

  • Mounts SMB/CIFS, AFP, FTP or NFS shares when you log in to your Mac
  • Retrieves passwords from OS X Keychain
  • Supports OS X Notification-Center
  • Easy to configure
  • Uses OS X components only

System Requirements

  • Mac OS X 10.8 or newer recommended
  • SMB/CIFS, AFP, FTP, NFS shares available in you network
  • Login credentials (username and password) for said shares

Get Mounty 0.15.1.2919 KiB

Use at your own risk (also see legal notices).

How does it work?

Install Mounty

Double-click the package Mounty.pkg you find in the disk image provided above and follow the instructions of the installer. Eventually the file ~/Scripts/mounty/mounty.conf will be opened in TextEdit so you can add the details of shares you want to mount at login. Further information about configuring Mounty can be found in the chapter below.

Configure Mounty

Details of all shares need to be put into the config file – usually ~/Scripts/mounty/mounty.conf). Entries in the value of variable mounty_shares are separated by semicolons, each with the following syntax:

protocol://user@server/share

To connect to a Windows share Documents on server 192.168.0.100 as user bill the entry should look like this:

smb://bill@192.168.0.100/Documents

Please find below an example for a configuration:

mounty_shares="smb://$USER@192.168.0.100/$USER;smb://$USER@192.168.0.100/Public;smb://$USER@192.168.0.100/Documents";

As you can see above, you can also use runtime variables to determine – for example – the user name. For the example to work, user names on client and server need to be identical.

Start Mounty

You can start mounty by hand: if – like during login – no specific configuration file name is provided, Mounty will use ~/Scripts/mounty/mounty.conf.

mounty.sh 

Mounty and Passwords

By default Mac OS X unlocks the user's keychain at login, so scripts can access keys through the command-line program security, so does mounty. For this to work all credentials needs to be stored in the keychain before you run it. Please ensure that you have mounted each share in Finder with the option Add to keychain once before you proceed.

What happens during login?

Mac OS X's inbuilt LaunchAgents trigger the execution of scripts in response to system events. Mounty depends on the event RunAtLoad.

The required LaunchAgent in ~/Library/LaunchAgents looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	...
	<key>ProgramArguments</key>
	<array>
		<string>bash</string>
		<string>-c</string>
		<string>~/Scripts/LaunchAgents/runatload.sh</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>

The array ProgramArguments, contains the shell name bash and two parameters, the latter being the actual skript. By executing the script inside the shell, globbing and the expansion of shell variables can be used within the script.

The above agent is used at login but can also be enabled manually:

launchctl load