mdsh.com/wiki


RecentChanges

TextFormattingRules
AllWikiTopics
OrphanedWikiTopics
ToDoWikiTopics
WikiLockList
RSS
Export2HTML

WikiSearch

SetUsername

StartingPoints
Home

Back to OSX:RunWhenNetworkChanges.

Diff OSX:RunWhenNetworkChanges

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>&lt;?xml version="1.0" encoding="UTF-8"?>
  +&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
  + "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  +&lt;plist version="1.0">
  +&lt;dict>
  + &lt;key>Label&lt;/key>
  + &lt;string>ifup.ddns&lt;/string>
  +  
  + &lt;key>LowPriorityIO&lt;/key>
  + &lt;true/>
  +  
  + &lt;key>ProgramArguments&lt;/key>
  + &lt;array>
  + &lt;string>/Users/mdsh/bin/route-add-leyborne&lt;/string>
  + &lt;/array>
  +  
  + &lt;key>WatchPaths&lt;/key>
  + &lt;array>
  + &lt;string>/etc/resolv.conf&lt;/string>
  + &lt;string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist&lt;/string>
  + &lt;string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist&lt;/string>
  + &lt;/array>
  +  
  + &lt;key>RunAtLoad&lt;/key>
  + &lt;true/>
  +&lt;/dict>
  +&lt;/plist></pre>[</html>]
  +  
  +Load the plist.
  +[<html>]<pre>$ sudo launchctl load /Library/Preferences/SystemConfiguration/com.mdsh.createRoutes.plist</pre>[</html>]


VeryQuickWiki Version 2.8.1 | Admin

All contents copyright mdsh.com (C) 2011-2023.