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.sh
has to be somewhere in launchd's PATH. To see whatlaunchd
's path is, uselaunchctl getenv PATH
If you need to change the PATH for
launchd
add a line to the file/etc/launchd.conf
line 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
launchd
to load it:launchctl load ~/Library/LaunchAgents/com.tjluoma.onnetworkchange.plist