Is there a way, with KM, to detect whether a vpn is active...?

Newbie question...
Is there a way, with KM, to detect whether a vpn is active...?
And if not to give a warning to the user?

Someone else may have a more robust idea, but this is all I could think of:

Log your IP when the VPN is inactive, using this macro:

VPN Check - Get My IP.kmmacros (20 KB)

Macro screenshot

This second macro will tell you whether your IP has changed, which might be because you've connected via a VPN:

VPN Check - IP Changed?.kmmacros (21 KB)

Macro screenshot

You'll need to log the non-VPN IP whenever you change network or reset your router. If your router uses a Dynamic IP function, then this isn't going to work.

1 Like

What VPN do you use? Depending on the software, we may be able to work up something that checks on command for VPN status specifically.

You could possibly just get your own ip:


And determine the range of possible values that represent the VPNs IPs or your ISPs IPs

sorry for the delay in reply.
I currently use 'ExpressVPN' but would happily change to something more suitable if required

You should be able to detect the status using the Execute an AppleScript action, with this script:

tell application "ExpressVPN"
    get state
end tell

Saving the results to a Keyboard Maestro variable would allow you to check it with an If Then Else action and act accordingly.

I would recommend the Display Text and/or Play Sound actions.
The Notification action is another option, but those can be easily missed by the user depending on notification settings.

If you get started on this and run into any issues, please post your macro so we can help troubleshoot.

thanks to everyone that replied
thanks to avtraino - I regretfully am away for a few days - but I will try that and get back to you if I get stuck.
thanks v much

1 Like