Automated script for connecting to the VPN.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Automated Juniper Network Connect VPN AppleScript


This is a script that will assist you in automating your VPN connection using Network Connect by Juniper Networks. It was designed for VPN access at Grand Valley State University, but contains nothing GVSU-specific. It should work for all versions of Network Connect on Mac OS X 10.6+, but it has been tested on GVSU's student VPN with Mac OS 10.6 Snow Leopard, Network Connect version 7.1.10 (21187).

Recommended Installation

There are a number of ways to use this AppleScript. This is what I recommend.

Create a bin directory for yourself if you don't already have it, and add it to your PATH:

mkdir ~/bin
echo 'export PATH=~/bin:"$PATH"' >> ~/.bashrc

Reload your shell (assuming bash) so these modifications take effect:

exec bash

Next, download the script:

curl > ~/bin/juniper

Make it executable:

chmod +x ~/bin/juniper

You can now use the script like so:

juniper myusername mypassword

The script will detect whether you are connected to the VPN. If not connected, it will start Network Connect and attempt to connect. If connected, it will sign out of the connection and quit Network Connect.

Shell Function

The previous instructions get it working, but don't really automate much. I wanted to be able to log in to the VPN by simply typing vpn at the terminal. I don't type passwords for websites or SSH, so I shouldn't have to type it for a VPN either. Add this shell function to your .bashrc to complete the configuration:

vpn () {
  juniper myusername mypassword &

It is backgrounded so you don't have to wait for the delay and get your shell back immediately.

Those who are security-minded may not like embedding their password directly into a shell function. If that describes you, you can use read to get the password instead:


vpn () {
  # -s: silent, turn off echo
  # -p: prompt
  read -sp 'VPN Password: ' password
  juniper myusername "$password" &


vpn () {
  # -s: silent, turn off echo
  read -s 'password?VPN Password: '
  juniper myusername "$password" &


As mentioned, this was created for use with GVSU's VPN. If you are a GVSU user, please use the following sample command-lines:


juniper studentusername studentpassword

See more about connecting in the GVSU VPN guide for students.


juniper facultyusername facultypassword

See more about connecting in the GVSU VPN guide for faculty.

But I use Windows or GNU/Linux!

I believe that Network Connect is scriptable on these operating systems, i.e., it has a command-line interface. I cannot confirm that yet. For some reason, on Mac OS X, Juniper decided not to give us this interface. Boo. That is what this AppleScript is designed to solve.


This AppleScript drew from two other scripts created for this purpose:

I also used a script from Macworld to help determine the "addresses" of the UI fields and button:

That script is committed in the repository as dumpobjects.applescript.