Reminder for VPN Connection?

Regularly, I forget to end a work-related VPN connection. I would like to have a notification after every 15 minutes I am connected. Is this possible? I am using no third-party software to establish this connection, just macOS functionality.

Thank you!

Chris

1 Like

Just come up with an idea. You can use Found Image action to look for the VPN icon on menu bar. I know the icon is different when it is connected or disconnected. And make the macro run every 15 mins. But to be honest, this isn't a good solution.

Drop into Terminal and see if this shows something when you are connected to the VPN:

scutil --nc list | fgrep -q '(Connected)

If it does, a script can be easily written to send a notification using Growl or terminal-notifier.

Feel free to hit me up if that one-liner works and you need some more pointers, I'll be happy to help. I think I've even got an old script of my own around here somewhere.

Thank you for your kind offer.

When I put scutil --nc list | fgrep -q '(Connected) in the terminal, it gives me a syntax error.

scutil --nc list | fgrep -q '(Connected)' however doesn't show anything.

Regards,

Chris

Whoops. Sorry about the missing quote mark. That's what I get for sloppy copy/pasting.

My recollection is that scutil --nc list can

man scutil says that --nc nc-arguments does the following:

Provides a set of commands for monitoring and interacting with VPN connections.
Use --nc help for a full list of commands.

However, I have seen in my own experience that it does not always report anything when I was using VPN Unlimited and Cloak, so I'm not sure what the distinction is that makes it work vs not work.

I guess it might be possible to use netstat to check if you are connected to your VPN host, but I'm not entirely sure.

Maybe someone else will have a better idea.

Late to the topic, but just a note that scutil --nc is a bit braindead now -- it does not report out IKEv2/IPSEC VPNs like one often sets up via Network Preferences.

I found a sight that has a workaround AppleScript. I don't use it, but I did derive my own to work with Keyboard Maestro -- my script just toggles the connection I want. I have it appear in my work's KM palette that is triggered by a hot key.

-- NOTE: first time this runs, you will need to grant it permission to access Accessibility
property vpn : "CIA" -- name of the entry to toggle
tell application "System Events"
  tell process "SystemUIServer"
    set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
    tell vpnMenu to click
    set vpnItem to a reference to (menu item 1 of menu 1 of vpnMenu where title contains vpn)
    tell vpnItem to click
  end tell
end tell