-
-
Save brozikcz/7c08366243ab953a4e883826d616b5d1 to your computer and use it in GitHub Desktop.
It's the apple script for the Cisco Secure Client app with the M$ SSO + authenticator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global ciscoClientMainWindowName | |
global ciscoClientBannerWindowName | |
global ciscoWindowTitle | |
global keychainItemName | |
global userPassword | |
set userLoginName to "user" | |
#set userPassword to "pass" #use the keychain item, the item and account name are the same `cisco_vpn` | |
set keychainItemName to "cisco_vpn" | |
set ciscoClientMainWindowName to "Cisco Secure Client" | |
set ciscoWindowTitle to "Cisco Secure Client - Login" | |
set ciscoClientBannerWindowName to "Cisco Secure Client - Banner" #be aware of size of dash | |
set formUser to "Sign in" | |
set formPassword to "Enter password" | |
set formSuccess to "Stay signed in" | |
set lang to user locale of (get system info) | |
considering case | |
if lang contains "cs_CZ" then | |
set ciscoWindowTitle to "Cisco Secure Client – přihlášení" | |
set ciscoClientBannerWindowName to "Cisco Secure Client – banner" | |
set formUser to "Přihlásit se" | |
set formPassword to "Zadat heslo" | |
set formSuccess to "Zůstat přihlášen" | |
end if | |
if lang contains "sk_SK" then #TODO Martas dopln :D | |
set ciscoWindowTitle to "Cisco Secure Client – přihlášení" | |
set formUser to "Přihlásit se" | |
set formPassword to "Zadat heslo" | |
set formSuccess to "Zůstat přihlášen" | |
end if | |
end considering | |
on getPassword() | |
set isPasswordSet to true | |
try | |
userPassword | |
on error message | |
set isPasswordSet to false | |
end try | |
if isPasswordSet then | |
return userPassword | |
end if | |
do shell script "security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | awk '{print $2}'" | |
if result is not "SecKeychainSearchCopyNext:" then | |
return (text 2 thru -2 of result) | |
else | |
display alert ("No " & keychainItemName & " keychain found!") ¬ | |
message ("Press OK to set up a " & keychainItemName & " keychain, or fill up the `userPassword` field.") as critical ¬ | |
buttons {"Cancel", "OK"} ¬ | |
default button ("OK") ¬ | |
cancel button "Cancel" | |
end if | |
return missing value | |
end getPassword | |
on waitForTextInWindow(searchText) | |
set startTime to (get current date) | |
tell application "System Events" | |
tell process ciscoClientMainWindowName | |
tell window ciscoWindowTitle | |
set duration to (get current date) - startTime | |
repeat until duration > 30 | |
set duration to (get current date) - startTime | |
try | |
set uiElem to ((value of static text of UI element of group 2 of UI element 1 of scroll area 1 of group 1 of group 1) as string) | |
#log uiElem | |
#log (uiElem contains searchText) | |
if (uiElem contains searchText) then | |
exit repeat | |
end if | |
end try | |
delay 0.5 | |
end repeat | |
if duration > 30 then | |
display alert ("The title " & searchText & " not found!") ¬ | |
message ("The script was canceled") as critical ¬ | |
buttons {"OK"} ¬ | |
default button ("OK") | |
error number -128 | |
end if | |
end tell | |
end tell | |
end tell | |
end waitForTextInWindow | |
on waitForWindow(windowName) | |
tell application "System Events" | |
set startTime to (get current date) | |
tell process ciscoClientMainWindowName | |
repeat until window windowName exists | |
delay 0.1 | |
set duration to (get current date) - startTime | |
if duration > 30 then | |
display alert ("The window " & windowName & " not found!") ¬ | |
message ("The script was canceled") as critical ¬ | |
buttons {"OK"} ¬ | |
default button ("OK") | |
error number -128 | |
end if | |
end repeat | |
end tell | |
end tell | |
end waitForWindow | |
activate application ciscoClientMainWindowName | |
tell application "System Events" | |
tell process ciscoClientMainWindowName | |
tell menu bar item 1 of menu bar 2 # show the window app | |
click menu item 3 of menu 1 | |
end tell | |
my waitForWindow(ciscoClientMainWindowName) | |
tell process "Cisco Secure Client" | |
keystroke return | |
end tell | |
my waitForWindow(ciscoWindowTitle) | |
my waitForTextInWindow(formUser) | |
tell window ciscoWindowTitle | |
tell text field 1 | |
keystroke userLoginName | |
key code 36 | |
end tell | |
end tell | |
my waitForTextInWindow(formPassword) | |
tell window ciscoWindowTitle | |
tell text field 1 | |
keystroke my getPassword() | |
end tell | |
key code 36 | |
end tell | |
my waitForTextInWindow(formSuccess) | |
tell window ciscoWindowTitle | |
key code 36 | |
end tell | |
set allWindows to "" | |
set startTime to (get current date) | |
repeat until allWindows contains ciscoClientBannerWindowName | |
set duration to (get current date) - startTime | |
if duration > 30 then | |
display alert ("The window " & ciscoClientBannerWindowName & " not found!") ¬ | |
message ("The script was canceled") as critical ¬ | |
buttons {"OK"} ¬ | |
default button ("OK") | |
error number -128 | |
end if | |
delay 0.1 | |
set allWindows to (get name of every window) as string | |
end repeat | |
delay 0.5 | |
tell window ciscoWindowTitle | |
key code 36 | |
end tell | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it?
You have two options:
Let's start with the first option: TURN IT INTO AN APPLICATION
Cisco-secure-client.scpt
with Script Editor (which is the default program used).File
, thenExport...
Application
forFile Format:
, andSign to Run Locally
forCode Sign:
Once you have your application compiled and ready:
Security & Privacy System Preferences
, go toPrivacy
, thenAccessibility
./Users/[yourhostname]/Applications
and then to the DockNow for the second option: KEEP IT AS A SCRIPT
Cisco-secure-client.scpt
with Script Editor (which is the default program used).Script Editor
, then clickPreferences
Show Script menu in menu bar
forScript Menu:
/Users/[yourhostname]/Library/Scripts
)Once you have saved the script inside your user's script folder:
Security & Privacy System Preferences
, go toPrivacy
, thenAccessibility
.Script Menu
Script Editor
. This is required if you want to run the script from the Script Editor.credits for README: https://github.com/communikein/anyconnect_autoconnect/blob/master/README.md