Skip to content

Instantly share code, notes, and snippets.

@y-fedorov
Last active January 17, 2023 07:50
Show Gist options
  • Save y-fedorov/3d9fee43ea07445a32f34172cf66e4a5 to your computer and use it in GitHub Desktop.
Save y-fedorov/3d9fee43ea07445a32f34172cf66e4a5 to your computer and use it in GitHub Desktop.
Cisco AnyConnect Secure Mobility Client on MacOS autofill password and connect (apple script) (version 2.0)
--
-- Yaroslav Fedorov <Y.Fedorov@reg40.net>
-- 11/14/2016
-- URL (http://indy-world.net/2016/11/cisco-anyconnect-secure-mobility-client-on-macos-autofill-password-and-connect-apple-script-version-2-0/)
set userLoginName to "<<user_login>>"
set keychainRecordName to "cisco_any_connect_auth"
set serverUri to "vpn.company.com"
on getPassword(keychainItemName)
local password
set password to do shell script ("/usr/bin/security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | cut -c 11-99 | sed 's/\"//g'")
if password contains "could not be found in the keychain" or password as string is equal to "" then
display alert "Password not found in the keychain" message "Certain tasks in this script need the administrator password to work.
You must create a new password in the OS X Keychain with a custom name, and set it with your administrator password, then edit this script." as critical
error "Password could not be found in the keychain."
else
return password
end if
end getPassword
set ciscoClientMainWindowName to "Cisco AnyConnect Secure Mobility Client"
activate application ciscoClientMainWindowName
tell application "System Events"
repeat until window 1 of process ciscoClientMainWindowName exists
end repeat
tell process ciscoClientMainWindowName
set disconnectButtonTitle to "Disconnect"
if exists (button disconnectButtonTitle of window 1) then
set result to display dialog "VPN is already connected." buttons {"Reconnect", "Cancel"} default button 2
tell window 1
click button disconnectButtonTitle
end tell
end if
repeat until static text "Ready to connect." of window 1 exists
end repeat
tell window 1
tell combo box 1
set focused to 1
set value to serverUri
end tell
click button "Connect"
end tell
set ciscoWindowTitle to "Cisco AnyConnect | " & serverUri
repeat until window ciscoWindowTitle exists
end repeat
tell window ciscoWindowTitle
tell text field 1
set value to userLoginName
end tell
tell text field 2
set value to my getPassword(keychainRecordName)
end tell
click button "OK"
end tell
end tell
end tell
@Homayuun
Copy link

how to implement this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment