SwiftBar/xbar plugin to establish VPN connections via OpenConnect and monitor connection status
- For original concept and initial work to: Jesse Jarzynka (file link)
- For modifications and improvement work to: Ventz Petkov (repo link)
- This script is based on the 2023-11-08 version of Ventz' BitBar plugin script available here.
- For the original vpnc-script to:
- For the menu bar icons to: FreeImages.com/VisualPharm
- Usage of the content in a project such as this is permitted according to the FreeImages license (May 2022 version)
- Disconnected icon: https://www.freeimages.com/icon/disconnected-5668900
- Connected icon: https://www.freeimages.com/icon/connected-5669666
This script provides a convenient way to control and monitor the OpenConnect VPN connection status from the macOS menu bar using either of these two apps:
Important
This script was only tested with an AnyConnect-based VPN server. It assumes a VPN setup requiring basic login credentials and at most a TOTP/HOTP-based 2FA setup.
Caution
During the setup process (see below), you will be required to save your credentials (meaning password and 2FA seed secret, if applicable) in the macOS keychain.
PROCEED AT YOUR OWN RISK
Needed are OpenConnect and optionally (depending on VPN server setup) oath-toolkit for 2FA functionality.
Installing can be done e.g. with the homebrew package manager:
brew install openconnect
brew install oath-toolkit
Check to see if OpenConnect works out of the box with the provided vpnc-script:
(Change the URL to your own VPN host and also change connection parameters if needed - see here)
sudo openconnect https://vpn.example.tld
If there are errors such as "... is not a recognized network service", see the README in the vpnc-script/
folder of this repo.
- Download the file
- Open it in a plain text editor or IDE of your choice
- Follow all steps in the "CONFIGURATION STEPS" section
- Copy/Move it to the SwiftBar/xbar script folder that you or the app chose
- Make sure the file is executable:
chmod +x openconnect.15s.sh
Tip
Hold the ⌥ Option key while clicking on the menu bar entry to bring up SwiftBar options that are hidden by default (only applies to SwiftBar).
Tip
Hold the ⌘ Command key to drag the menu bar entry to the desired spot.
Note
When using SwiftBar, the script (and thus the menu entries) will update itself when the menu bar item is clicked in order to provide an accurate uptime. In case of connection loss, the script (and thus the icon) will update itself after around 15 seconds. Should you want to tweak this value, e.g. because you are using xbar where refresh-on-click is not an available feature or for performance reasons, you can rename the script according to this guide.