Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 4 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.

share|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
@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

A launchd agent watching /etc/resolv.conf, and two network related .plist files under /Library/Preferences/SystemConfiguration/ seems to work for me (in Mac OS X 10.8.4):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
<plist version="1.0">





I had previously only used /etc/resolv.conf, but there were cases where that wasn't enough.

share|improve this answer
This was very helpful to me, but there's an error (found by [this answer][1]): the opening <plist version="1.0"> tag is missing. [1][apple.stackexchange.com/a/181127/56862] –  LiberalArtist Apr 16 at 4:53
@patrix (and LiberalArtist): Thanks for the correction. I hadn't noticed, because it worked for me in 10.8.5. I guess later versions are more strict. –  mivk Apr 18 at 15:16

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.

share|improve this answer

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

share|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

ControlPlane: “Context Sensitive Computing”

ControlPlane is a direct port of MarcoPolo and in fact, much of the configuration from MarcoPolo still works with ControlPlane, just better! ControlPlane supports 32 and 64bit Intel based Macs running Snow Leopard and higher.

enter image description here enter image description here enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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