Writing an Alfred Workflow About VPN Connection
Part of the team’s services is deployed on the internal network. Usually, when we are remotely processing some work, we need to connect to the VPN.
Although Cisco’s AnyConnect client tool can be used, it cannot save passwords for automatic login, so the OpenConnect becomes a good choice, which is an open-source command-line tool.
This article is based on the macOS platform, using Alfred’s Workflow feature to improve the portability of OpenConnect connections.
Open Alfred via a shortcut key, enter specific keywords and enter the user password after selecting the function.
Alfred is an award-winning app for macOS which boosts your efficiency with hotkeys, keywords, text expansion and more. Search your Mac and the web, and be more productive with custom actions to control your Mac.
The free version has similar functions to Spotlight. It can be used as a quick application launcher, calculator, dictionary and other all-in-one applications. After purchasing
Powerpack, it unlocks
Workflows as its special features. It is recommended to buy the Mega version in the official site.
Workflow is literally meant workflow, also knows as something like a shortcut. I think it has a certain degree of similarity with
IFTTT. The following figure is the Workflow I am using.
First, make sure that OpenConnect is installed on the macOS system.
brew install openconnect
There are already Shell scripts that can connect and disconnect the VPN, so the main goal of this article is to transform existing scripts below.
- Make the best use of existing scripts without rebuilding the wheels.
- The steps should be as short as possible.
Create a new
Workflow, add each component, and connect as shown in this figure.
Transform existing script to NSAppleScript section.
- Improve various types of information and export scripts for distribution within the team.
The script needs high enough privileges, but we can’t escalate privileges directly through sudo in Alfred.
NSAppleScript to escalate privileges, as shown in the following figure. We can also achieve similar goals by modifying user group permissions, but the latter is more invasive to the system.
Interactive code does not work。
Transformed the script to change the interactive part of inputting passwords to pass parameters.
After improving Workflow instructions, copyright notices, version descriptions, we can now export it to team members.
- Copyright Declaration: All articles are original and follow the CC BY-NC-SA 4.0 protocol.