Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Macnovice101

macrumors newbie
Original poster
Jan 14, 2016
1
0
Hi there. I have an applescript that I've been using to set up a tunnel when I have to log into a particular VPN Network. It allows me to still access the interest while using VPN. The Applescript stopped working once I upgraded to El Capitan and I get an error every time. Please help. I have no idea how to fix this

THE SCRIPT
# VpnInit
# ---
# an AppleScript utility to connect your vpn,
# restore local default route and add selected
# routes directed to the VPN only
# thus you'll end up sending only selected
# traffic through the VPN, while the rest
# goes through your local default gateway
# as usual
# ---
# released "as is" under the terms of GPL v2.
# Copyright © 2011 Gianpaolo Del Matto
#
# r0.1 initial release 2011/12/29

# the name of your vpn connection
#
set _vpn_name to "TriWest"

# your local default gateway
#
set _default_gw to (do shell script "netstat -rn -f inet | grep -w default | grep -v utun0 | head -n 1 | awk '{print $2}'")

# your remote networks to pass via VPN, separate multiple with comma
# like so: {"1.2.3.4/30", "5.6.7.8/30"}
#
set _networks to {"10.49.20.5/6"}


# your super-user (root) password
# actually needed to bypass the prompts
# leave empty to get prompted
#
set _sudo_password to "REMOVED FOR POST"


# ##################################################################
# DO NOT CHANGE ANYTHING BELOW
# ##################################################################


# kindly borrowed from
# http://www.macosxautomation.com/applescript/uiscripting/index.html
# make sure that support for assistive devices is enabled
#
tell application "System Events"
if UI elements enabled is false then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script requires access for assistive devices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the forthcoming security dialog." with icon 1
end tell
set UI elements enabled to true
if UI elements enabled is false then
display dialog "This script cannot run while access for assistive devices is disabled." & return & "Exiting now." buttons {"OK"} with icon 2
return "user cancelled"
end if
end if
end tell

# now dive into the VPN setup part
#
tell application "System Events"
set _if_tunnel to "utun0" # do not change, will be auto-detected, just giving a reasonable default
tell current location of network preferences
if exists service _vpn_name then
# try to connect the VPN service if it's disconnected
#
if current configuration of service _vpn_name is not connected then
connect service _vpn_name
end if

# give it some time to settle
#
set _retval to false
repeat until (_retval) is true
set counter to 0
repeat while counter is less than 16
# exit if we get connected
#
if current configuration of service _vpn_name is connected then
set _retval to true
exit repeat
end if

# opt for exit if still not connected after 15 seconds
#
if counter is equal to 15 then
display dialog "VPN '" & _vpn_name & "' is still not connected after 15 seconds. Do you want to keep waiting?" with title "VPN still not connected" buttons {"Yes", "No"}
if button returned of result is "No" then
# bail out if user decided not to wait any longer
#
set _retval to true
return
else
# otherwise reset the counter so we can trigger again
#
set counter to 0
end if
end if

set counter to counter + 1
delay 1
end repeat
end repeat

# now go to post processing and to the following:
# - delete default route via vpn
# - restore original default route
# - add specific routes to vpn
#
if current configuration of service _vpn_name is connected then
# restore local default route
#
do shell script "route delete default" password _sudo_password with administrator privileges
do shell script "route add default " & _default_gw password _sudo_password with administrator privileges

# inject custom routes via VPN
#
repeat with _network in _networks
do shell script "route add -interface " & _network & " utun0" password _sudo_password with administrator privileges
end repeat
end if
else
# bail out if the VPN service does not exist
#
display dialog "Given VPN '" & _vpn_name & "' does not exist. Please check the name"
end if
end tell
end tell

THE ERROR
error
"System Events got an error: Can’t get current configuration of service \"TriWest\" of current location of network preferences." number -1728 from current configuration of service "TriWest" of current location of network preferences
 

Partron22

macrumors 68030
Apr 13, 2011
2,655
808
Yes
On some system updates it helps to copy the text of the script to a text file, then paste it into a new script window, and compile that anew.
That said, do you have the service TriWest configured on your new system?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.