title: Does "launchctl unload" on OSX pass "ProgramArguments" to the target application?
body: <p>I am attempting to set up a <code>.plist</code> file for use with <code>launchctl</code> on OSX.  When run from the command line (not using <code>launchctl</code>), our application is executed as:</p>
  
  <pre><code>/path/to/ourapp
  </code></pre>
  
  <p>... and to terminate our application, we type:</p>
  
  <pre><code>/path/to/ourapp -k
  </code></pre>
  
  <p>... which causes the new instance of <code>ourapp</code> to properly kill the previous instance that is running.</p>
  
  <p>Now I set up a <code>.plist</code> file to control execution of the application via <code>launchctl</code>, as follows:</p>
  
  <pre><code>// start.plist
  &lt;dict&gt;
      &lt;key&gt;Disabled&lt;/key&gt;
          &lt;false/&gt;
      &lt;key&gt;Label&lt;/key&gt;
          &lt;string&gt;ourapp&lt;/string&gt;
      &lt;key&gt;ProgramArguments&lt;/key&gt;
          &lt;array&gt;
              &lt;string&gt;/path/to/ourapp&lt;/string&gt;
          &lt;/array&gt;
      &lt;key&gt;OnDemand&lt;/key&gt;
          &lt;false/&gt;
      &lt;key&gt;UserName&lt;/key&gt;
          &lt;string&gt;daniel347x&lt;/string&gt;
      &lt;key&gt;SHAuthorizationRight&lt;/key&gt;
          &lt;string&gt;system.preferences&lt;/string&gt;
  &lt;/dict&gt;
  </code></pre>
  
  <p>... and I execute it at the command line, as follows:</p>
  
  <pre><code>launchctl load /path/to/start.plist
  </code></pre>
  
  <p>This works successfully to launch the application.</p>
  
  <p>Unfortunately, when creating a <code>stop.plist</code>, as follows (the only difference is the addition of the <code>-k</code> argument):</p>
  
  <pre><code>// stop.plist
  &lt;dict&gt;
      &lt;key&gt;Disabled&lt;/key&gt;
          &lt;false/&gt;
      &lt;key&gt;Label&lt;/key&gt;
          &lt;string&gt;ourapp&lt;/string&gt;
      &lt;key&gt;ProgramArguments&lt;/key&gt;
          &lt;array&gt;
              &lt;string&gt;/path/to/ourapp&lt;/string&gt;
              &lt;string&gt;-k&lt;/string&gt;  // &lt;-- only difference is adding this argument
          &lt;/array&gt;
      &lt;key&gt;OnDemand&lt;/key&gt;
          &lt;false/&gt;
      &lt;key&gt;UserName&lt;/key&gt;
          &lt;string&gt;daniel347x&lt;/string&gt;
      &lt;key&gt;SHAuthorizationRight&lt;/key&gt;
          &lt;string&gt;system.preferences&lt;/string&gt;
  &lt;/dict&gt;
  </code></pre>
  
  <p>... and executing via</p>
  
  <pre><code>launchctl unload /path/to/stop.plist
  </code></pre>
  
  <p>... the application does NOT terminate ... therefore, it seems that when using <code>launchctl</code>, the application is not being executed equivalently to </p>
  
  <pre><code>/path/to/ourapp -k
  </code></pre>
  
  <p>Can someone tell me what <code>launchctl unload</code> is really doing - i.e. is it calling the application from the command line with the given arguments, or not - and what I can do to get my <code>stop.plist</code> to work when using <code>launchctl unload</code>, given whatever it is doing?</p>