title: Launch Agent Not Starting
body: <p>I’m trying to make a launch agent that starts <a href="https://github.com/Just-Some-Bots/MusicBot/blob/master/run.py" rel="nofollow noreferrer">a Python script</a>. It should run when there’s a network connection but it doesn’t do that. <code>launchctl list</code> says it’s loaded:</p>
  
  <pre><code>launchctl list | grep test.Flopsey.DiscordMusicBot
  -   0   test.Flopsey.DiscordMusicBot
  </code></pre>
  
  <p>When I start it with <code>launchctl start test.Flopsey.DiscordMusicBot</code> it works fine. The .plist file (which is stored under ~/Library/LaunchAgents) looks like this:
  </p>
  
  <pre><code>&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;test.Flopsey.DiscordMusicBot&lt;/string&gt;
      &lt;key&gt;ProgramArguments&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5&lt;/string&gt;
          &lt;string&gt;/path/to/MusicBot/run.py&lt;/string&gt;
      &lt;/array&gt;
      &lt;key&gt;EnvironmentVariables&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;PATH&lt;/key&gt;
          &lt;string&gt;/bin:/usr/bin:/usr/local/bin&lt;/string&gt;
      &lt;/dict&gt;
      &lt;key&gt;StandardOutPath&lt;/key&gt;
      &lt;string&gt;/path/to/MusicBot/log.log&lt;/string&gt;
      &lt;key&gt;StandardErrorPath&lt;/key&gt;
      &lt;string&gt;/path/to/MusicBot/log.log&lt;/string&gt;
      &lt;key&gt;WorkingDirectory&lt;/key&gt;
      &lt;string&gt;/path/to/MusicBot&lt;/string&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;
  </code></pre>
  
  <p>I’m new to launchd and I followed <a href="http://www.launchd.info/" rel="nofollow noreferrer">this tutorial</a>. I think the solution to my problem is very basic but I have no idea what it could be. I’ve also made another similar agent and it works fine (unlike the music bot it’s only one file).</p>
  
  <h2>Update</h2>
  
  <p>Thanks to <a href="https://stackoverflow.com/users/2197430/lcc">@LCC</a>’s comment I realised that using <code>NetworkState</code> doesn’t work anymore on OS X 10.10 and higher. Since the script exits when it can’t connect to the Internet I can just set <code>KeepAlive</code> to <code>&lt;true/&gt;</code> and set up a <code>ThrottleInterval</code> so launchd restarts the script after a cooldown if it couldn’t connect.</p>