Start VPN when waking up

On my Linode server (great company and service BTW), I had setup a VPN for me, but after upgrading to Ubuntu 14.04, I had no time to reinstall it.

So yesterday, I grabbed a free account on NoLimitVPN (because NSA and Google, you know) and I’ve been using it without any problems. (I’m no expert in security, but since NoLimitVPN is managed by a french company and their VPN is hosted on RamNode.com in the Netherlands, I expect a minimum of privacy).

The only problem I had was that the VPN doesn’t connect automatically when my Mac wakes up. DuckDuckGoing (what’s the official or usual verb ?) (because I don’t use Google anymore), I only found AppleScripts running in background and connecting the VPN. Since I don’t want something running in the background on my old and faithful iMac, I looked for alternatives.

This is the solution I’ve set up on my Mac:

To start the VPN (named “VPN”, duh), I use a terminal command

scutil --nc start VPN

Instead of this AppleScript (found on StackOverflow)

    
tell application "System Events"
    tell current location of network preferences
        set myConnection to the service "VPN"
        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

To start the VPN when waking up, I use SleepWatcher (a tool I use to pause ArqBackup when my Mac wakes up) and I put this line in my ~/.wakeup file:

scutil --nc start VPN > /dev/null 2>&1

Voila, problem solved.