I need to get an automation to turn off my vpn after a certain minutes of inactivity.
I would do this either with an alarm or a timed focus mode deactivation. Both can be used as trigger for an automation. Use whatever suits you more, but Focus Modes are probably easier to handle than alarms (as you can‘t edit or delete them with shortcuts).
With a shortcut you can set an alarm to a specific time or you can set a Shortcut to on for a certain amount of seconds, minutes or hours. After you set that up, just create a personal automation with that alarm or that Focus Mode deactivating as a trigger and add this to your automation:
I’ve also wanted this. As of right now there’s no out of the box shortcut action to toggle vpn
Using shortcuts, Can we set an alarm or deactivate the focus mode after every two minutes of my screen lock?
You can make your Shortcut loop every 2 minutes by doing something like this and make an automation that runs this shortcut when your looper Focus Mode deactivates.
The think is, after trying your method, my vpn is turning off every after two minutes of it get connected even im using it. I need it to turned off after two minutes of inactivity.
Oh I see, so the problem is the measurement of “inactivity”. This is indeed tricky.
You could make an automation when opening and closing any relevant app. You can select multiple apps at once when setting up such an automation. Just save the current time (when opening or closing an app) to a reminder or to a text file somewhere in your file system, and make an if condition around the VPN action, that‘s only true when the difference between the time saved in your reminder/file and the time of the check is bigger or equal to 120 seconds.
EDIT: But then it will still interpret it as “inactivity” if you have an app open for more than two minutes …. You have to implement some kind of check if an app has been closed after it was opened. And something like this is afaik only possible by creating automations for each of your apps, because it‘s impossible to get the name of the app that‘s currently open.
It’s too hard for me to understand actually… anyway thank you so much for your time