Launchd.plist KeepAlive key in Leopard

There is a new “KeepAlive” key for launchd property lists in Leopard; it takes a boolean or a dictionary of conditions in which to keep a job alive. One of those, NetworkState, is may prove useful for systems administrators (assuming, as is sometimes hard to do with launchd, that it works as advertised … the author at Apple has admitted that documented functions just didn’t work at all in Tiger).

Excerpted from the launchd.plist man page:

NetworkState
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.”

I’m certainly going to have to try that out when I get a chance, since I have in the past had a need to run scripts when network configuration changes occurred. I hope launchd delivers in this case, as it has always held so much promise.

I’ve resorted to editing Kicker.xml, using SystemConfiguration because launchd didn’t ultimately have a way to do the same thing and SystemConfiguration is the source. This, even though it was preferable to install only a launchd property list to configure a job rather than edit Kicker.xml — a configuration file that shipped with Tiger that Apple could overwrite during any of their software updates.

[Thanks to Mike Bombich, by way of Geoff.]

Update: Geoff wanted me to know that Kicker.xml is gone in Leopard and that “Apple is a tool.” As you can see, we’re always free around here with the constructive criticism.

Another update: Quinn the Eskimo (!) replies and says this probably won’t work as intended, when transitioning from one IP address to another.