Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question


Edit the file /Applications/ 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/ :

umount /Volumes/TimeCapsule


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


Warning : Configuration files client.(up|down) 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.

share|improve this answer
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) – Cameron Conner Aug 22 '10 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 Aug 22 '10 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 – Cameron Conner Aug 22 '10 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.