Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set app_name to "UserNotificationCenter"
- set dialog_text to "VPN Connection"
- set pwd to "yourpass"
- on find_window_by_static_text(appname, staticText)
- log "Searching " & appname & " for " & staticText
- tell application "System Events"
- set allApps to (get name of every application process) -- get all apps
- if allApps contains appname then -- find the app if it's running
- set allWin to (get every window of application process appname) -- get all the windows for our app
- set numWin to count allWin -- count the number of windows
- repeat with winNum from 1 to numWin
- set aWin to window winNum of application process appname
- set allText to (get value of every static text of aWin)
- if allText contains staticText then
- log "fwbst winnum: " & winNum
- return winNum
- end if
- end repeat
- end if
- end tell
- return null
- end find_window_by_static_text
- on vpn_connect(vpn_name, password, app_name, dialog_text)
- tell application "System Events"
- tell current location of network preferences
- set VPNservice to service vpn_name -- name of the VPN service
- if exists VPNservice then
- connect VPNservice
- end if
- end tell
- end tell
- repeat with x from 1 to 20
- log "vc loop " & x
- delay 0.1
- set winNum to find_window_by_static_text(app_name, dialog_text)
- log "winNum is: " & winNum
- if winNum is not null then
- exit repeat
- end if
- end repeat
- if winNum is null then
- log "Could not find the VPN Connection window"
- return null
- end if
- tell application app_name to activate
- tell application "System Events"
- perform action "AXRaise" of item winNum of (get every window of application process app_name)
- keystroke password
- key code 36
- end tell
- delay 1
- end vpn_connect
- vpn_connect("mig33vpn", pwd, app_name, dialog_text)
- vpn_connect("mig33sin02", pwd, app_name, dialog_text)
Add Comment
Please, Sign In to add comment