I spend a lot of time connected to a Palo Alto VPN using their GlobalProtect app. I have always wanted a way to connect/disconnect without having to use my mouse to go find the menubar icon, click it, and then click Connect/Disconnect. I finally figured out how to automate this using AppleScript and decided to share it in hopes that even one other person finds this useful. I have tested this using both macOS 10.14 and 11.4.
tell application "System Events" to tell process "GlobalProtect" click menu bar item 1 of menu bar 2 click button 2 of window 1 click menu bar item 1 of menu bar 2 end tell
The first click opens up the GlobalProtect menubar application. The second click actually does the Connect or Disconnect, and the final click simply closes the window. This all happens very quickly. As with most AppleScript, you are going to need to allow whatever app you run this is Full Accessibility of macOS.
I have also posted this as a gist if you have any comments/improvements.
This part is silly, but I have a 12-key “macropad” keyboard at my desk. I am using Keyboard Maestro to assign key combinations and scripts to it; so I now have a 1 key-press way to toggle my VPN status.