title: MacOS - Using script with launchd - startup, login, logoff, shutdown?
body: <p><strong>MacOS High Sierra</strong></p>
  
  <p>I want to run this script on startup, login and shutdown, logoff.</p>
  
  <p>The script looks like this and is working successfully from terminal:</p>
  
  <pre><code>#!/bin/sh
  find /private/my/tmp -mindepth 1 -maxdepth 1 -type d -not -name -specialfolder -exec rm -r {} \;
  find /private/my/tmp -mindepth 1 -maxdepth 1 -exec rm -r {} \;
  </code></pre>
  
  <p>I have used the Automater to create an .app placed my script in Login Items and this works when logging in, however this does not solve the issue of startup, logoff or shutdown so I do not think that this is the answer.</p>
  
  <p>Reading around, it seems I need to use <code>launchd</code>, but I really can't figure out how to do this with my script.</p>
  
  <p>Can anyone please help?</p>
  
  <p>Edit: For using with launchd, how does this look? I am sure to have some mistakes, hopefully someone can guide me in the right direction.</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;EnvironmentVariables&lt;/key&gt;
      &lt;dict&gt;
        &lt;key&gt;PATH&lt;/key&gt;
        &lt;string&gt;/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:&lt;/string&gt;
      &lt;/dict&gt;
      &lt;key&gt;Label&lt;/key&gt;
      &lt;string&gt;com.startup&lt;/string&gt;
      &lt;key&gt;Program&lt;/key&gt;
      &lt;string&gt;/private/myscripts/startup.sh&lt;/string&gt;
      &lt;key&gt;RunAtLoad&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;KeepAlive&lt;/key&gt;
      &lt;false/&gt;
      &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;        
      &lt;true/&gt;
    &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>