Mac equivalent of /etc/network/if-up.d

Does anyone know what the Mac equivalent of /etc/network/if-up.d is?

I would like to run a script when my network connection is established. This appears to by easy enough on Linux systems using if-up.d, but I can't find anything equivalent in Mac OS X. Does anyone have any suggestions?

Thanks!

The original MacBook Pro, Mac OS X (10.4.11)

Posted on Jan 1, 2010 7:13 PM

Reply
6 replies

Jan 1, 2010 8:10 PM in response to ThatGuy!

I would go over to <http://MacOSXHints.com> and do some searching.

I've read about several approaches on the MacOSXHints web site. One involved using SleepWatcher, which would run when you laptop (or any type of Mac) wakes from sleep, it will run any script you desire. Since most laptop network state changes occur when they away in a new location, SleepWatcher is a workable substitute.

It seems there is a com.apple.airport.preferences.plist changes when your network changes, so it might be possible to setup a launchd "WatchPaths" that executes a script when there is a network change.

You could get a utility such as MacroPolo that can trigger actions when your network changes (or maybe it is when your laptop wakes from sleep).

There are other utilities similar to MarcoPolo, such as LocationX, etc...

Finally, you could always give Apple a suggestion for such a service via <http://www.apple.com/feedback>

Jan 1, 2010 8:26 PM in response to BobHarris

Thanks for the suggestions. I haven't found anything on macosxhints yet, but I will keep looking.

I would prefer to integrate directly with the system to determine when a network connection is made, rather than relying on third party applications. At the very least I should be able to get notified when a network connection is established using whatever mechanism any third party application uses!

Monitoring com.apple.airport.preferences.plist is not a bad idea. It does have one or two drawbacks though. For example that would only tell me if a network connection was made through Airport, not if one is made through ethernet. Also, I don't know if it would allow me to differentiate between a network connection event and a network disconnection event.

If I don't find anything else I'll certainly suggest it to Apple.

Thanks again!

Jan 2, 2010 3:53 PM in response to ThatGuy!

Check launchd - the standard process launcher on Mac OS X. It includes the ability to run a script/process when the network comes up or down.

From man launchd.plist:

NetworkState <boolean>
If true, the job will be kept alive as long as the network is up,
where up is defined as at least one non-loopback interface being up
and having IPv4 or IPv6 addresses assigned to them. If false, the
job will be kept alive in the inverse condition.

Jan 2, 2010 6:14 PM in response to LittleSaint

LittleSaint wrote:
This used to be easy with the Kicker.bundle and Kicker.xml in /System/Library/SystemConfiguration, but those disappeared with 10.5.


It is still pretty easy. I wrote a little launchd program to monitor my VPN connection and inject my own name servers after it comes up. I used the System Configuration API. SCDynamicStoreCreate is the important function. You could probably still cobble something together with the scutil tool. It has a notification and timeout capability.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mac equivalent of /etc/network/if-up.d

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.