Because I need to use a onetime token to connect to my VPN I need to enter the password manually and therefor I did a versions of the same script that will wait for the status of service to change like this:
set VPNserviceName to "My VPN Connection" -- Change this to your VPN connection name
set scConnectCommand to "scutil --nc start '" & VPNserviceName & "'"
if "Disconnected" is equal to getVPNServiceStatus(VPNserviceName) then
log "Running command " & scConnectCommand
do shell script scConnectCommand
repeat until not "Connecting" is equal to getVPNServiceStatus(VPNserviceName)
log "Waiting for service to be connected"
delay 2
end repeat
end if
on getVPNServiceStatus(VPNserviceName)
return do shell script "scutil --nc status '" & VPNserviceName & "' | head -1"
end getVPNServiceStatus
Just though I would share. :-)