MacOS – How to automount a network share once OpenVPN has connected? (Using Tunnelblick)

afpautomountmacosvpn

Does anyone know how to automatically mount a network share once a VPN connection using Tunnelblick has connected?

Right now I have to connect and then do a cmd+K in the finder to connect to the AFP share. It'd be nice if it would connect automatically.

The share doesn't have a password (TimeCapsule without any passwords, and no, not using it for backup, we use it for a fileserver).

Best Answer

1.

Edit the file /Applications/Tunnelblick.app/Contents/Resources/client.up.osx.sh and add these commands at the end of the file, just before exit 0 :

su USERNAME -c '
mkdir /Volumes/TimeCapsule
mount_afp afp://afp_username@server/volumename /Volumes/TimeCapsule
'
open /Volumes/TimeCapsule

Replace USERNAME with your username on the system.

2.

Then add the following at the end of /Applications/Tunnelblick.app/Contents/Resources/client.down.osx.sh :

umount /Volumes/TimeCapsule

3.

Do not forget to check the set nameserver option for your configuration :

nameserver

Warning : Configuration files client.(up|down).osx.sh are executed for every connections made using OpenVPN.

This could also be made using launchd for watching if the vpn connection is up, but I don't know how to use launchd.