0

I have an Applescript that will connect my VPN profile when my computer boots. However, if my computer sleeps, the VPN connection is broken and the script doesn't reconnect it. Also, if there is a server disconnect, the script doesn't reconnect it either.

Here's my script:

tell application "System Events"
    tell current location of network preferences
        set myVPN to the service "MyVPN"
        if myVPN is not null then
            if current configuration of myVPN is not connected then
                connect myVPN
            end if
        end if
    end tell
    return 60
end tell
end idle

I'm not familiar enough with Applescript to know if this is possible, but with some other scripting/programming languages, you can listen for events and respond to them.

Does Applescript have the ability to respond to system events and is there a system event that fires when a VPN profile disconnects?

  • No, generally speaking, AppleScript cannot listen for events. You could run a script in the background that continuously polls the name and connection status of the current network configuration, but I don't think that's a good route to take. AppleScriptObjC can be used to create an event listener to monitor for system wake-from-sleep, but I'm not sure what the overhead is on this and how cost effective such a script would be. Your best best is probably to use a third-party option. – CJK Oct 2 '18 at 18:41

You must log in to answer this question.

Browse other questions tagged .