OSX launchd: Reliable means of monitoring wired connection?

1.5k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

1
On

In theory, you should be able to sign up for notifications in your launchd plist. I have never actually gotten it to work, but I didn't try all that hard either. This is what I was told would work:

<key>LaunchEvents</key>
<dict>
    <key>com.apple.distnoted.matching</key>
    <dict>
        <key>com.apple.system.config.network_change</key>
        <dict>
            <key>Name</key>
            <string>com.apple.system.config.network_change</string>
        </dict>
    </dict>
</dict>