Skip to content

Instantly share code, notes, and snippets.

@bholt
Last active December 14, 2015 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bholt/5119857 to your computer and use it in GitHub Desktop.
Save bholt/5119857 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSWorkspace</key>
<key>SystemConfiguration</key>
<dict>
<key>State:/Network/Global/IPv4</key>
<dict>
<key>command</key>
<string>~/Dropbox/dev/scripts/vpn_connect_disconnect.bash</string>
</dict>
</dict>
</dict>
</plist>
#!/bin/bash
# called by PyMacAdmin: crankd.
# ~/Library/Preferences/com.googlecode.pymacadmin.crankd.plist
function connect {
/usr/bin/env osascript <<EOF
tell application "System Events"
tell current location of network preferences
set vpnConn to the service "Sampa"
if vpnConn is not null then
if current configuration of vpnConn is not connected then
connect vpnConn
end if
end if
end tell
end tell
EOF
}
function disconnect {
/usr/bin/env osascript <<EOF
tell application "System Events"
tell current location of network preferences
set vpnConn to the service "Sampa"
if vpnConn is not null then
if current configuration of vpnConn is connected then
disconnect vpnConn
end if
end if
end tell
end tell
EOF
}
if [ $(/usr/sbin/networksetup -getinfo Wi-Fi | grep -c 'IP address:') == '2' ]
then
echo 'connected'
connect
else
echo 'not connected'
disconnect
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment