This answer is about starting ProtonVPN when connected to network, and not about the general question.
Use the OpenVPN Configuration file
See the ProtonVPN's site for how to manually configure OpenVPN for ProtonVPN.
This guide will walk you through how to create, download and set up the OVPN file from ProtonVPN.
Once you have done everything on that site open the app Advanced Network Configuration. If you can't find this app by searching for apps, then open a terminal and enter:
nm-connection-editor
Select the network you want to use VPN in. For example, Ethernet Connection, and click on the gear icon at the bottom left corner of the window.

Go to the General Tab and then select the check box next to Automatically connect to VPN.
Then use the drop-down menu next to it to select the ProtonVPN set up you have already done.
Repeat for each WiFi network you want to use VPN.
See 20.04LTS NetworkManager VPN - Always on for more.
A Script to run at login
Write a script that checks if there is any internet connection and if ProtonVPN has no active connections. If these conditions are met, the script will start ProtonVPN using the commandline client.
Create a script called /home/your_username/bin/start_proton
. You may need to create the folder /home/your_username/bin/
to keep all your scripts. The content of the script is:
#!/bin/bash
# Sccript:/home/username/bin/start_proton
# Purpose: Check if there is internet and if proton is not running, then start VPN
STATUS=$(protonvpn-cli status | grep No) # Checks VPN is not running
ping -c1 -4 google.com > /dev/null # Check Internet is working
if [[ $? -eq 0 && $STATUS == "No active Proton VPN connection." ]]; then
echo $STATUS
protonvpn-cli connect --fastest
else
echo "FAIL: Either no Internet Or VPN is running already"
fi
Note: I have used the --fastest
option for the VPN server choice. You may edit that line and use other options that suits you.
Make the script executable by Right-Clicking the script in Files going to its Properties > Permission Tab.
Test the script
make sure you are connected to the Internet and ProtonVPN is not running.
Open a terminal and enter the command:
start_proton
If all goes well you will see ProtonVPN starting up and connecting to its server.
Add to Startup Applications
Now open the Startup Applications app and click on the Add button. Fill up the fields as below:
Name: Start VPN
Command: /home/username/bin/start_proton
Comment: starts VPN if there is any Internet
Replace username
with your username for this computer.
Click on the Save button to save the new entry. Make sure the check box next to Start VPN is checked.
Next time when you start your computer and login ProtonVPN will start.
Hope this helps
man networkmanager-dispatcher
– user535733 Aug 17 '22 at 18:39