KeepAlive with NetworkState not working for agent I'm trying to automatically execute a Python script every day, but it requires an Internet connection (to send emails, etc.). So I fixed the date and hour at which it needs to be executed, but if there's no network available, I want it to be executed as soon as it finds a network. I thought that the following would do just what I need:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
  &lt;dict&gt;

    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.example&lt;/string&gt;

    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/bin/python&lt;/string&gt;
        &lt;string&gt;/path/to/my/script.py&lt;/string&gt;
    &lt;/array&gt;

    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;dict&gt;
      &lt;key&gt;Hour&lt;/key&gt;
      &lt;integer&gt;10&lt;/integer&gt;
      &lt;key&gt;Minute&lt;/key&gt;
      &lt;integer&gt;30&lt;/integer&gt;
    &lt;/dict&gt;

    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;dict&gt;
      &lt;key&gt;NetworkState&lt;/key&gt;
      &lt;true/&gt;
    &lt;/dict&gt;

  &lt;/dict&gt;
&lt;/plist&gt;


It works fine when I have an Internet connection at 10:30, but when I don't have network available but only get it back at, say, 11:00, it does not execute the script and does nothing for the rest of the day.

What did I do wrong?

Many thanks,
Check the manpage (man launchd.plist) to see if NetworkState is implemented.

For me, on macOS Mojave, it is not:

KeepAlive &lt;boolean or dictionary of stuff&gt;

This optional key is used to control whether your job is to be kept continuously running
or to let demand and conditions control the invocation. The default is false and therefore
only demand will start the job. The value may be set to true to unconditionally keep the
job alive. Alternatively, a dictionary of conditions may be specified to selectively control
whether launchd keeps a job alive or not. If multiple keys are provided, launchd ORs them,
thus providing maximum flexibility to the job to refine the logic and stall if necessary.
If launchd finds no reason to restart the job, it falls back on demand based invocation.
Jobs that exit quickly and frequently when configured to be kept alive will be throttled
to conserve system resources.

    NetworkState &lt;boolean&gt;
    This key is no longer implemented as it never acted how most users expected.