See & Toggle Wi-Fi and VPN in one touchbar button

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');

Screen Shot 2020-03-23 at 6.37.22 PM

This is what my VPN is named.

wonder if you do not have vpnutil installed.

Try in terminal: /usr/local/bin/vpnutil or just vpnutil

I don't. Is that a BTT command, or something on the system I need to install?

I tried searching for vpnutil but I don't seen anything. Is this a BTT extension, or something on OS X I need to install?

Here is VPNUTIL required for my script

vpnUtil.zip (9.6 KB)

1 Like

Thank you!

Works like a charm. Thanks again!

Hello,

first of all thank you very much for the tool.

Unfortunately I have a problem. When I click the button, the VPN connects, but when I click it again it doesn't disconnect.

I took your preset and only changed the VPN name. In addition, the button color does not change when the VPN is connected.

Can nobody help me?

@K2DesignLab can you help me please?

Run this in terminal and report back what it shows while connected and not connected to VPN.

ifconfig -lu

1 Like

VPN connected: lo0 en0 en3 en4 en1 en2 p2p0 awdl0 llw0 utun0 utun1 utun2 utun3 utun4 utun5 en5 utun6

VPN disconnected: lo0 en0 en3 en4 en1 en2 p2p0 awdl0 llw0 utun0 utun1 utun2 utun3 utun4 utun5 en5

@K2DesignLab

I found the mistake. I have entered utun6 instead of ipsec, now I can connect and disconnect VPN. But unfortunately, that's not gonna change icon. You got another tip for me?

Check and change the same ipsec to your utun6 on the button widget code.

1 Like

Thanks thanks thanks, it works perfekt!

@K2DesignLab Unfortunately I still have a problem. For me, the value utun6 changes constantly. Sometimes it's utun6, sometimes it's utun2 or utun3. I have no clue whats the cause of this. Can you insert an either or for the values?

You're probably using a VPN like Tunnelblick or other openVPN and its not using a default or single interface. You may be able to force it to use a default interface or force it to close all interfaces before starting and after stopping. Worth a try...

I use a VPN from my Fritzbox. How can I force a standard interface? I'm a little overwhelmed

thanks guys, this works, I tried it with ClearVPN using utun3