Searching for (a) Pulse (CLI tool)
I’ve been searching for a way to suspend the Pulse Secure VPN connection from the command line for a while.
jamCommand doesn’t do it.
Pulse Launcher doesn’t work on Mac.
TL;DR
Use Automator to control Pulse Secure through the menu item.
Here are the finished scripts.
Notes
-
Download the automator scripts here.
-
Open the .zip, move
vpn-suspend
andvpn-resume
to~/Desktop/
-
Open Automator, open
vpn-suspend
, modify the script’s menu item as needed.on run {input, parameters} -- System events are crazy slow, so ignore responses and kill them after. ignoring application responses tell application "System Events" click menu bar item 1 of menu bar 2 of application process "Pulse Secure" end tell end ignoring -- Modify the delay as needed. We're not waiting for the UI (see above). delay 0.1 -- so slow https://en.it1352.com/article/1b646ad9e7224b26b7229c31bc9196f3.html do shell script "killall System\\ Events" tell application "System Events" -- YOU NEED TO CHANGE THE NAME OF THE MENU ITEM HERE click menu item "MyConnection-East-MAC" of menu 1 of menu bar item 1 of menu bar 2 of application process "Pulse Secure" click menu item "Suspend" of menu 1 of menu item "MyConnection-East-MAC" of menu 1 of menu bar item 1 of menu bar 2 of application process "Pulse Secure" end tell end run
-
Save the Automator script.
-
Right-click
vpn-suspend
on~/Desktop
and select “Open.” This will give you an opportunity to add it to the the list of trusted apps. -
Change
vpn-suspend
the same way. -
You can run these from the command line with
open ~/Desktop/vpn-suspend.app
. -
Create aliases for
open ~/Desktop/vpn-suspend.app
andopen ~/Desktop/vpn-resume.app
Example in Fish
# ~/.config/fish/config.fish
alias vpns="open ~/Desktop/vpn-suspend.app"
alias vpnr="open ~/Desktop/vpn-resume.app"
Demo
Troubleshooting
If you get errors when running like this
…you may need to add (or remove then add) it in System Preferences > Security & Privacy.
If you see an error like
The action “Run AppleScript” encountered an error: “System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of application process “Pulse Secure”. Invalid index.”
… try running the command again. It’s time-based, so it may have tried to run faster it could have. If this is persistent, try modifying the script in Automator to use a larger delay. You’ll need to re-trust the app each time you modify it, FYI.