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.


searches

Notes

  1. Download the automator scripts here.

  2. Open the .zip, move vpn-suspend and vpn-resume to ~/Desktop/

  3. 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
    
  4. Save the Automator script.

  5. 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.

    r-click

  6. Change vpn-suspend the same way.

  7. You can run these from the command line with open ~/Desktop/vpn-suspend.app.

  8. Create aliases for open ~/Desktop/vpn-suspend.app and open ~/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

no-access

…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.