I have implemented a VPN auto connect option via Applescript [see code]. It works like a charme there's only one problem. Every time when i open my MacBook I get this [see printscreen] notification. A few seconds later it reconnects as it should. How can I stop that notification from showing up? It's very annoying.

on idle
tell application "System Events"
    tell current location of network preferences
        set myConnection to the service "my vpn name"
        if myConnection is not null then
            if current configuration of myConnection is not connected then
                connect myConnection
            end if
        end if
    end tell
    return 120
end tell end idle

It's Dutch (sorry for that ;)) It says "Connection has been broken, Please try reconnecting

2 Answers 2


The problem comes because the VPN server is killing the connection sometime after the mac goes to sleep.

Try disconnecting the VPN before going to sleep, automatically, using sleepwatcher as described in this Q&A.

  • Isn't there a way to add something into the Apple Script? I don't have any experience in terminal ;)
    – Bram
    Oct 31, 2014 at 13:25

I created a script and launch agent to accomplish the same thing. This method avoids that message(tested on OS X 10.11.3). 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 did this through an Apple Script App, the app icon will always be in your dock. I prefer to have this running automatically in the background.

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


  • How is your script different than the one the user posted? answering directly here is better for the site. Also, this user wants to side step the notification - please edit your post to explicitly state that it does or does not answer that core part of this question.
    – bmike
    Jan 28, 2016 at 18:57

You must log in to answer this question.

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