set client VPN on when...

I am trying to write a script that will log into our VPN server when ever a user is not on our wifi SSID. I have 2 problems I am trying to solve:

  1. I only want it to run when the user in not within our network (SSID)
    and
  2. I want it to run not only when the user boots/logins but also when the user just wake up the laptop.

There used to be a command that would return the SSID of the current network “mySSID” seems to no longer to work.

here is when I have that only works when the user logs into the box:

on idle
tell application “System Events”
tell current location of network preferences
set VPNService to service “myVPNclient”
if exists VPNService then
connect VPNService
end if
end tell
end tell
end idle

Thanks for any help

db