Guest User

Untitled

a guest
Mar 3rd, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set app_name to "UserNotificationCenter"
  2. set dialog_text to "VPN Connection"
  3. set pwd to "yourpass"
  4.  
  5. on find_window_by_static_text(appname, staticText)
  6.     log "Searching " & appname & " for " & staticText
  7.     tell application "System Events"
  8.         set allApps to (get name of every application process) -- get all apps
  9.         if allApps contains appname then -- find the app if it's running
  10.             set allWin to (get every window of application process appname) -- get all the windows for our app
  11.             set numWin to count allWin -- count the number of windows
  12.             repeat with winNum from 1 to numWin
  13.                 set aWin to window winNum of application process appname
  14.                 set allText to (get value of every static text of aWin)
  15.                 if allText contains staticText then
  16.                     log "fwbst winnum: " & winNum
  17.                     return winNum
  18.                 end if
  19.             end repeat
  20.         end if
  21.     end tell
  22.     return null
  23. end find_window_by_static_text
  24.  
  25. on vpn_connect(vpn_name, password, app_name, dialog_text)
  26.     tell application "System Events"
  27.         tell current location of network preferences
  28.             set VPNservice to service vpn_name -- name of the VPN service
  29.             if exists VPNservice then
  30.                 connect VPNservice
  31.             end if
  32.         end tell
  33.     end tell
  34.    
  35.     repeat with x from 1 to 20
  36.         log "vc loop " & x
  37.         delay 0.1
  38.         set winNum to find_window_by_static_text(app_name, dialog_text)
  39.         log "winNum is: " & winNum
  40.         if winNum is not null then
  41.             exit repeat
  42.         end if
  43.     end repeat
  44.    
  45.     if winNum is null then
  46.         log "Could not find the VPN Connection window"
  47.         return null
  48.     end if
  49.    
  50.     tell application app_name to activate
  51.     tell application "System Events"
  52.         perform action "AXRaise" of item winNum of (get every window of application process app_name)
  53.         keystroke password
  54.         key code 36
  55.     end tell
  56.     delay 1
  57. end vpn_connect
  58.  
  59.  
  60. vpn_connect("mig33vpn", pwd, app_name, dialog_text)
  61. vpn_connect("mig33sin02", pwd, app_name, dialog_text)
Add Comment
Please, Sign In to add comment