Is there any way to run a script when a network interface comes up in Mac OS X?

I've tried putting a script named ip-up in /etc/ppp but it doesn't seem to fire when I disconnect and reconnect to a wireless network.

I'd prefer not to have to run a cron job to constantly check whether the network status has changed. In some linux distros, you can accomplish this by putting a script in /etc/network/if-up.d/ . Is there anything similar for Mac OS X?

link|improve this question
feedback

3 Answers

up vote 2 down vote accepted

You could try MarcoPolo or one of the similar utilities listed on its website. Location Changer looks promising if you're a minimalist.

link|improve this answer
I'd prefer to do this without installing additional programs. However, the Location Changer link was very helpful since it includes a launchd configuration for running the program on a network change. – Zxaos Oct 20 '10 at 14:01
Zxaos: Sure, that's why I included it. It's basically a launchd/bash script template for whatever you want. Saves you from writing the boilerplate code yourself. – Daniel Beck Oct 20 '10 at 15:09
if I can bother you to look at this very-relevant q (superuser.com/questions/265861) I'd much appreciate it (how to start and stop vpn from command line on OSX). Excuse the soliciting, I'll delete this comment in a few hours regardless. Thanks in any case! – Yar Apr 2 '11 at 20:45
1  
@Yar Not a problem, but it's past midnight in central Europe right now, so please wait half a day or so before pinging me again (and please do so if nothing comes up in the meantime, it's an interesting question). – Daniel Beck Apr 2 '11 at 23:15
Thanks @Daniel Beck. As you perhaps already saw, using Applescript was the answer. It probably is to many things on OSX, but I often forget it. – Yar Apr 3 '11 at 13:34
feedback

You should consider using crankd, which precisely allows you to run scripts in response to many system events such as network changes, filesystem activity, application launching, etc.

As I couldn't find any sensible documentation, I also wrote a small blog post on getting started using crankd.

link|improve this answer
feedback

Start with launchd. You might be able to similar functionality using it.

link|improve this answer
launchd seems like it's a step in the right direction, especially if I can figure out how other programs use it to detect network changes. – Zxaos Oct 20 '10 at 13:58
@Zxaos, launchd seems like a step in the right direction, but there is no reliable way to make it detect network changes. See my answer for a solution using crankd instead. – Juan A. Navarro Mar 24 '11 at 13:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.