Skip to content

Commit 03b3852

Browse files
committed
added support to connect or disconnect VPN for >= mohave
1 parent f160d91 commit 03b3852

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

Diff for: lazy-connect

+39-35
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ function _lazy_connect() {
134134
end tell
135135
end tell
136136
end connectVpn
137-
138137
connectVpn("$vpn_name", "$password", "$autofill")
139138
EOF
140139
}
141140

142141
function _lazy_connect_mojave() {
143142
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 /},"
145146

146147
_lazy_connect_get_totp $2
147148
local autofill=$3
@@ -162,47 +163,50 @@ function _lazy_connect_mojave() {
162163
fi
163164

164165
osascript <<EOF
165-
on connectVpn(vpnName, password, autofill)
166+
on connectOrDisconnectVpn(vpnName, disconnectedVpnName, connectedVpnName, password)
166167
tell application "System Preferences"
167168
reveal pane "Network"
168169
activate
169-
170170
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"
197193
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
198203
end tell
204+
end tell
199205
end tell
200-
201206
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")
206210
EOF
207211
}
208212

0 commit comments

Comments
 (0)