If Wi-Fi is on, and VPN is connected, the button says the Wi-Fi SSID (in green)
If Wi-Fi is on, but VPN is disconnected, the button says the Wi-Fi SSID (in red)
Actions
Tap button once to toggle Wi-Fi
Long-tap button to toggle VPN
Installation & Configuration 1. Allow Scripting & Configure Shared Secret
If your BetterTouchTool is configured to use a shared secret, get it from the advanced settings dialog (see here, chapter "security"). If the shared secret field is empty, you can ignore the shared secret altogether and do not need to change this part of the scripts. If you would like to use one, or if it's already configured with other plugins, copy the shared secret to your clipboard.
Toggle Wi-Fi
The script tries to figure out your Wi-Fi network adapter's BSD name (like en0, en1, etc.) to toggle it.
VPN
It doesn't matter what kind of VPN you have, as long as you configured it directly through macOS's System Preferences (Network option) and as long as they start with "VPN " (e.g. "VPN USA", "VPN MyCompany"). The script to toggle VPN is configured in BetterTouchTool's "Other"-Tab.
This script finds all VPN connections and sorts them alphabetically. That means, that if you have 2 VPN networks, let's say "VPN 1 MyCompany" and "VPN 2 MyCompany", the alphabetically first one will be the default one it auto-connects to.
Known limitation: if your VPN is not a L2TP one, please adjust the word it searches for in the Touchbar-button and toggle vpn script. (I only have this kind, so I don't know exactly what other values could show up. If you have such a case, let me know and I'll implement it9o
I've sunk an hour into researching what the right commands and keywords are for an openVPN with no luck. Then again, I don't know what I'm doing when it comes to networks. Any ideas on where to start?
Took me a little time to create this one, not sure if its perfect for every occasion, but works flawless right now.
I have my VPN button coded as below. Your VPN must be setup in Apple Network Prefs, you will use that Service Name below (Mine = NordVPN). Notice the "ipsec1" that is my VPN interface (When VPN is ACTIVE) when checking for interfaces using terminal command: ifconfig -lu
set activeInterfaces to do shell script "ifconfig -lu"
if activeInterfaces contains "ipsec1" then
display notification "NordVPN Service Disconnected" with title "VPN Disconnecting..." sound name "Bottle"
set service_name to "NordVPN"
if service_name is not null then
do shell script (do shell script "/usr/local/bin/vpnutil stop "" & service_name & """)
end if
else
display notification "NordVPN Service is Connected " with title "VPN Connecting..." sound name "Bottle"
if activeInterfaces does not contain "ipsec1" then
set service_name to "NordVPN"
if service_name is not null then
do shell script (do shell script "/usr/local/bin/vpnutil start "" & service_name & """)
end if
end if
end if
Advanced Configuration: Run AppleScript Show return
set activeInterfaces to do shell script "ifconfig -lu"
if activeInterfaces contains "ipsec1" then
return "VPN ON"
else
return "VPN OFF"
end if
Is anyone having a solution to connect a IKEV2 VPN, or retrieve vpn status in OSX Catalina ?
scutil nor Applescript are not working anymore, cannot find a solution
trying the script return me this:
/bin/bash: -c: line 10: syntax error near unexpected token do' /bin/bash: -c: line 10: do shell script (do shell script "/usr/local/bin/vpnutil stop "" & service_name & """)'
I can start manually my interface with vpnutil start and shut it down with vpnutil stop whithout problems.
if I try to simply run vpnutil start MyVpn with BTT, I'm given a /bin/bash: vpnutil: command not found.
Sorry as I'm new with BTT. Using the new configuration interface, what I have to call ? a shell script.
Butcher to put the "Advanced configuration" AppleScript ? your script work nicely and return the state on my connection correctly. Sorry for the dumb question, I'm a bit... Lost
Ive attached the preset for you to import. Its AppleScript, using shell scripts, not a shell script in BTT.
You will need to change/replace my coded name "VPN Network-NAME" in my code to what you have in Apple Network Settings for your VPN connection.
I downloaded this, but I can't get it to connect/disconnect from my VPN. The icon is correct, whether I'm connected or disconnected to VPN. If I'm connected, I'll press the lock, then it says "Disconnecting" then it does nothing. Any ideas?
set activeInterfaces to do shell script "ifconfig -lu"
if activeInterfaces contains "ipsec" then
display notification "VPN Service Disconnected" with title "VPN Disconnecting..." sound name "Bottle"
set service_name to "nVPN"
if service_name is not null then
do shell script (do shell script "/usr/local/bin/vpnutil stop \"" & service_name & "\"")
end if
else
display notification "VPN Service is Connected " with title "VPN Connecting..." sound name "Bottle"
if activeInterfaces does not contain "ipsec" then
set service_name to "nVPN"
if service_name is not null then
do shell script (do shell script "/usr/local/bin/vpnutil start \"" & service_name & "\"")
end if
end if
end if
returnToBTT('please return a string like this somewhere in your script');