@@ -134,14 +134,15 @@ function _lazy_connect() {
134
134
end tell
135
135
end tell
136
136
end connectVpn
137
-
138
137
connectVpn("$vpn_name ", "$password ", "$autofill ")
139
138
EOF
140
139
}
141
140
142
141
function _lazy_connect_mojave() {
143
142
vpn_name=$1
144
- osx_vpn_name=" ${vpn_name/ Connect / } , Not Connected"
143
+ osx_vpn_name_not_connected=" ${vpn_name/ Connect / } , Not Connected"
144
+ osx_vpn_name_connected=" ${vpn_name/ Connect / } , Connected"
145
+ osx_vpn_name=" ${vpn_name/ Connect / } ,"
145
146
146
147
_lazy_connect_get_totp $2
147
148
local autofill=$3
@@ -162,47 +163,50 @@ function _lazy_connect_mojave() {
162
163
fi
163
164
164
165
osascript << EOF
165
- on connectVpn (vpnName, password, autofill )
166
+ on connectOrDisconnectVpn (vpnName, disconnectedVpnName, connectedVpnName, password )
166
167
tell application "System Preferences"
167
168
reveal pane "Network"
168
169
activate
169
-
170
170
tell application "System Events"
171
- tell process "System Preferences"
172
- tell window 1
173
- repeat with r in rows of table 1 of scroll area 1
174
-
175
- if (value of attribute "AXValue" of static text 1 of r as string) is equal to "$osx_vpn_name " then
176
- select r
177
- end if
178
- end repeat
179
-
180
- tell group 1
181
- click button "Authentication Settings…"
182
- end tell
183
-
184
- tell sheet 1
185
- set focused of text field 2 to true
186
- set value of text field 2 to "$password "
187
- click button "Ok"
188
- end tell
189
-
190
- click button "Apply"
191
-
192
- delay 1
193
- tell group 1
194
- click button "Connect"
195
- end tell
196
-
171
+ tell process "System Preferences"
172
+ tell window 1
173
+ repeat with r in rows of table 1 of scroll area 1
174
+ if (value of attribute "AXValue" of static text 1 of r as string) contains vpnName then
175
+ select r
176
+ exit repeat
177
+ end if
178
+ end repeat
179
+ if (value of attribute "AXValue" of static text 1 of r as string) is equal to disconnectedVpnName then
180
+ log "Connecting to vpn " & vpnName
181
+ tell group 1
182
+ click button "Authentication Settings…"
183
+ end tell
184
+ tell sheet 1
185
+ set focused of text field 2 to true
186
+ set value of text field 2 to password
187
+ click button "Ok"
188
+ end tell
189
+ click button "Apply"
190
+ delay 1
191
+ tell group 1
192
+ click button "Connect"
197
193
end tell
194
+ else if (value of attribute "AXValue" of static text 1 of r as string) is equal to connectedVpnName then
195
+ log "Disconnecting from vpn " & vpnName
196
+ tell group 1
197
+ click button "Disconnect"
198
+ end tell
199
+ else
200
+ log "Couldn't connect or disconnect the VPN, didn't find any exact match. The network found was: "
201
+ log (value of attribute "AXValue" of static text 1 of r as string)
202
+ end if
198
203
end tell
204
+ end tell
199
205
end tell
200
-
201
206
quit
202
- end tell
203
- end connectVpn
204
-
205
- connectVpn("$osx_vpn_name ", "$password ", "$autofill ")
207
+ end tell
208
+ end connectOrDisconnectVpn
209
+ connectOrDisconnectVpn("$osx_vpn_name ", "$osx_vpn_name_not_connected ", "$osx_vpn_name_connected ", "$password ")
206
210
EOF
207
211
}
208
212
0 commit comments