Advertisement
Mordredd

Captive Network Assistant VPN script

Jan 30th, 2013
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "System Events"
  2.     set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
  3. end tell
  4.  
  5. set wlanssid to do shell script "networksetup -getairportnetwork en1 | cut -c 24-"
  6. connectVPN(wlanssid)
  7. if isRunning then
  8.     sendGrowl("VPNCONNECT", "Connecting VPN", wlanssid)
  9. end if
  10.  
  11.  
  12. on connectVPN(SSID)
  13.     tell application "System Events"
  14.         tell current location of network preferences
  15.             local VPNService
  16.             if (SSID = "XXXXXXXXXX") then --WLAN Name
  17.                 set VPNService to service "XXXXXXX-VPN" -- VPN Name
  18.                 set isConnected to connected of current configuration of VPNService
  19.                 if not isConnected then
  20.                     connect VPNService
  21.                 end if
  22.             end if
  23.         end tell
  24.     end tell
  25. end connectVPN
  26.  
  27. on sendGrowl(growlName, growlTitle, growlDescription)
  28.     try
  29.         tell application "GrowlHelperApp"
  30.             set the allNotificationsList to {growlName}
  31.             set the enabledNotificationsList to {growlName}
  32.             register as application ¬
  33.                 "Show " & growlName all notifications allNotificationsList ¬
  34.                 default notifications enabledNotificationsList ¬
  35.                 icon of application "Network Utility"
  36.             notify with name growlName ¬
  37.                 title growlTitle ¬
  38.                 description growlDescription ¬
  39.                 application name "Show " & growlName
  40.         end tell
  41.     on error growlError
  42.         display dialog "Growl Error:" & return & growlError
  43.     end try
  44. end sendGrowl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement