3

Anyone familiar with launchd on Mac OS X, specifically the NetworkState (bool) key in KeepAlive section of a .plist file?

From the man pages, launchd should call an executable when there is no network connectivity on the Mac, when the plist is configured like this:

...
<key>KeepAlive</key>
<dict>
    <key>NetworkState</key>
    <false/>
</dict>
...

This seems to work okay, However, once a valid network connection is established (defined as the Mac having at least one non-loopback IPv4/6 address), launchd should stop calling the executable (because the NetworkState flag should prevent it).

The behavior I am seeing, though, is that launchd keeps calling my program regardless of the Mac's network connectivity! It’s as if launchd is completely ignoring the NetworkState flag.

Does anyone know how to make this work so that launchd will only call a program when there’s no network connection, and stop calling it once a network connection is established?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Eric Baker
  • 357
  • 4
  • 14
  • Really? Nothing? Tumbleweed? Isn't anyone else trying to do something like this? – Eric Baker Jun 21 '11 at 20:25
  • You're not alone here. I've been playing around with this as well and haven't been able to get it to work as expected. There doesn't seem to be a lot out there on this, but depending on what you're looking to do, check out (http://tech.inhelsinki.nl/locationchanger/). That plist watches a directory to detect network changes. There may be help in there. – Alan W. Smith Aug 11 '11 at 19:07
  • I created a plist for connecting to my wifi every ten seconds if NetworkState was false, as my Mac looses connection every night, but even when it reconnected and I assume NetworkState is true, it still kept reconnecting every ten seconds making the internet unusable. it didn't work as I thought it would. – Kurt L. Jul 15 '19 at 05:51

1 Answers1

6

I've been trying to tackle this same problem for a while, and today I finally realized my misunderstanding.

When any of KeepAlive's conditions evaluate to true, that means "ensure this process is running." When none of them evaluate to true, that means "do not ensure this process is running," not, as I had hoped, "ensure this process is not running."

Nick Novitski
  • 206
  • 2
  • 6