I recently asked a question How to auto connect to VPN upon login/boot? which got answered well using apple script .

I want to extend this question to the following problem:

The vpn connection should be activated automatically when not connected to my home wifi. (e.g. i'm surfing in Starbucks) The default state would be vpn activated but it includes an "opt-out" for my home wifi.

2 Answers 2


Perhaps something like ControlPlane would do the job for you?


Here is another option:

I created a script and launch agent to accomplish this. The agent calls a shell script every 30 seconds and tries to ping an IP address that is static on the vpn network. If it cannot ping that IP it enables your vpn connection. If you are home, the script will be able to ping that address and will not connect to the vpn.

Clone the project below and follow the directions in the readme. The end result is an installer package that will place a launch agent plist file in /Library/LaunchAgents/ and a shell script in /Library/Application Support/melonsmasher/.

Be sure to edit the shell script(auto-vpn) with your VPN connection name and an IP address that is on the VPN network. You can change the run interval in the plist file(com.melonsmasher.autovpn.plist).


You must log in to answer this question.

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