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).

2 Answers 2



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.


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

umount /Volumes/TimeCapsule


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


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.

  • Did you forget a line? It isn't working, and when I stick the code directly into Terminal, it asks for my password. Possibly that's why it isn't running in the up script too? Actually, removing the su line (and it's counterpart ' below) doesn't work either. I would expect it to at least make the dir and possibly connect, but not let me access the folder. (and yep, set nameserver is checked) Commented Aug 22, 2010 at 1:16
  • The su command is used to impersonate someone (you in this case). Both scripts are executed as root and he doesn't need a password when using su but another user will need one. If the command inside su isn't working alone, the problem comes from here. What exactly did you type ?
    – Studer
    Commented Aug 22, 2010 at 11:28
  • Okay, wasn't sure that tunnelblick would run it as root. If I take the command inside of the su and drop it directly into terminal, it runs fine. If I remove the su part and just have the command in the up script, nothing happens. # Generate an updated plist with the proper path DIR="$(dirname "${0}")" LEASE_WATCHER="${DIR}/LeaseWatch.plist" sed -e "s|\${DIR}|${DIR}|g" "${LEASE_WATCHER}.template" > "${LEASE_WATCHER}" launchctl load "${LEASE_WATCHER}" # autoconnect server2 mkdir /Volumes/Data mount_afp afp:// /Volumes/Data open /Volumes/Data exit 0 Commented Aug 22, 2010 at 17:29

I have just succeeded to auto-mount NFS after having connected VPN and auto-unmount before discconect with Tunnelblick (3.7.3 on macOS High Sierra).

At first, I had the same problem with Cameron Conner. Still, Studer's answer was quite helpful for me.

Instead of Studer's client.(up|down).osx.sh, I placed two lines in the .ovpn:

up (path to your connected.sh)
down (path to your pre-disconnect.sh)

Then create and edit these connected.sh and pre-disconnect.sh.


sudo mkdir /Volumes/NFS
sudo mount -P /Volumes/NFS


sudo umount /Volumes/NFS

I don't know about TimeCapsule manipulation. So above process is about NFS. I think you can arrange it for TimeCapsule.

I think the point Cameron and I got stucked was su or sudo. And, to avoid password is another problem. My solution to that was sudoers.

Edit /etc/sudores with visudo. Modify the %admin entry from:

%admin ALL=(ALL) ALL



Unless your account is not an admin, it should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .