7

Is this possible? I want to have one Shortcut which works like a On/Off button for a VPN (similar to a wireless on/off Button on many laptops). To achieve this, I would probably need a script involving the network manager?

Reason: I have to connect and disconnect my VPN a lot. Every of these connects or disconnects takes three clicks, which adds up, plus my mouse is very insensitive (even in the most sensitive setting)

I have LM 18.1 Mate, with 4.8 Kernel.

2 Answers2

12

I just found the solution, very straight forward.

Simply creating two shortcuts, with the commands below:

for VPN ON: nmcli con up servername

for VPN OFF: nmcli con down servername

enter image description here

3

I took this a bit further and thought I'd share it here.

I created a .sh script and an associated .desktop file so I can easily invoke this from Gnome.

The shell script I've placed in ~/.local/bin/vpn-toggle.sh

#!/usr/bin/env sh

CONNECTION_NAME=Home

if [[ -n $(nmcli connection show $CONNECTION_NAME | grep "VPN connected") ]]; then nmcli connection down $CONNECTION_NAME; else nmcli connection up $CONNECTION_NAME; fi

Remember to change the CONNECTION_NAME to the name of your connection.

The .desktop file I've placed in ~/.local/share/applications/vpn-toggle.desktop

[Desktop Entry]
Type=Application
Terminal=false
#Icon=/path/to/icon/icon.svg
Name=VPN Toggle
Exec=/home/tons/.local/bin/vpn-toggle.sh

You need to fix the Exec path to match your system. I couldn't get it to work with ~ and didn't care to investigate further.