macosplistosx-mountain-lionlaunchdlaunch-agent

OSX launchd: Reliable means of monitoring wired connection?


I don't want to watch /Library/Preferences/SystemConfiguration to handle [network] location changes b/c doing so results in my script getting run twice in a row for every change.

Watching /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist works well for wifi, but won't catch when, say, I am on WiFi and plug in my thunderbolt ethernet.

Is there a plist I can watch for wired connections? Or am I stuck adding a second LaunchAgent that polls every 5 seconds and then touches some file in ~/Library when wired ethernet changes to an active state?


Solution

  • this variation will work

    <key>LaunchEvents</key>
    <dict>
        <key>com.apple.notifyd.matching</key>
        <dict>
            <key>com.apple.system.config.network_change</key>
            <dict>
                <key>Notification</key>
                <string>com.apple.system.config.network_change</string>
            </dict>
        </dict>
    </dict>    
    

    but it will produce a LOT of notifications... it took some searching in the deamons piles to discover the right syntax :) enjoy