A shell script and launchd plist for running commands whenever a Mac's network location information is updated.
This is a very basic script for you to start with to create your own actions "on network change".
Note! The .plist file (see below) will only run a program called onnetworkchange.sh so once you have made your own, be sure to rename it appropriately.
This is a slightly more complicated file, showing some of the more advanced things that you can do with this.
This is a launchd plist file which tells launchd to the run the onnetworkchange.sh command any time the folder "/Library/Preferences/SystemConfiguration/" changes (which happens whenever the network settings are changed).
In order for this to work, you must move two files to the correct location.
-
A script called
onnetworkchange.shhas to be somewhere in launchd's PATH. To see whatlaunchd's path is, uselaunchctl getenv PATHIf you need to change the PATH for
launchdadd a line to the file/etc/launchd.confline this:setenv PATH /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin -
Next, the com.tjluoma.onnetworkchange.plist file has to be moved to ~/Library/LaunchAgents/. Once it is in place, tell
launchdto load it:launchctl load ~/Library/LaunchAgents/com.tjluoma.onnetworkchange.plist