Line 0: |
| | + | !!!How To run a script when the networking location changes!!!
|
| | + |
|
| | + |
|
| | + | Create the script you want to run.
|
| | + | [<html>]<pre>$ vim /Users/mdsh/bin/route-add</pre>[</html>]
|
| | + | [<html>]<pre>#!/bin/bash
|
| | + |
|
| | + | route delete 10.0.0.0/8 10.64.0.253
|
| | + | route add 10.0.0.0/8 10.64.0.253</pre>[</html>]
|
| | + |
|
| | + | Make the script runnable.
|
| | + | [<html>]<pre>$ chmod a+x /Users/mdsh/bin/route-add</pre>[</html>]
|
| | + |
|
| | + | Create a plist which defines a script to be run upon the detection of a change in a networking file.
|
| | + | [<html>]<pre>$ sudo vim /Library/Preferences/SystemConfiguration/com.mdsh.createRoutes.plist</pre>[</html>]
|
| | + | [<html>]<pre><?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>Label</key>
|
| | + | <string>ifup.ddns</string>
|
| | + |
|
| | + | <key>LowPriorityIO</key>
|
| | + | <true/>
|
| | + |
|
| | + | <key>ProgramArguments</key>
|
| | + | <array>
|
| | + | <string>/Users/mdsh/bin/route-add-leyborne</string>
|
| | + | </array>
|
| | + |
|
| | + | <key>WatchPaths</key>
|
| | + | <array>
|
| | + | <string>/etc/resolv.conf</string>
|
| | + | <string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
|
| | + | <string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
|
| | + | </array>
|
| | + |
|
| | + | <key>RunAtLoad</key>
|
| | + | <true/>
|
| | + | </dict>
|
| | + | </plist></pre>[</html>]
|
| | + |
|
| | + | Load the plist.
|
| | + | [<html>]<pre>$ sudo launchctl load /Library/Preferences/SystemConfiguration/com.mdsh.createRoutes.plist</pre>[</html>]
|