Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Trigger a script on a network change in macosx 1. Move locationchanger to a location of your wish and make it executable. 2. Edit LocationChanger.plist with the location of locationchanger. 3. Move LocationChanger to ~/Library/LaunchAgents/LocationChanger.plist 4. Execute the following on a terminal: launchctl load ~/Library/LaunchAgents/Locatio…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
<plist version="1.0">
#! /bin/bash
#logFile = $HOME/bin/locationchanger.log
logFile = /dev/null
# reroute only when on mobimate wifi
# determine wifi ssid
ssid=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'`
echo `date` Location: $ssid >> $logFile
if [ "$ssid" = "MyWifi" ]; then
# we are on MobiMate, need to reroute
echo `date` Rerouting... >> $logFile
# get sudo privileges and perform the rerouting
osascript -e "do shell script \"
route -nv add >> $logFile
route -nv add >> $logFile
\" with administrator privileges"
# we are on other wifi, no need to reroute
echo `date` No need to reroute >> $logFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment