Last active
December 14, 2015 17:09
-
-
Save bholt/5119857 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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