10.11.3 - launchd to start a job either at startup or at time of day I am attempting to use launchd to have SelfControl be active from 8am to 8pm. My first attempt was to just use launchd and have a little bash script which starts self control (for 12 hours) at 8am, but this isn't really flexible enough because if my laptop is off at 8am then obviously nothing happens. 

Any advice on a better way to approach this problem or modify my current approach?

Here is the .plist 

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//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;my.selfControlScheduler&lt;/string&gt;
  &lt;key&gt;Program&lt;/key&gt;
     &lt;string&gt;/Users/ira/Documents/coding/self_control/sc_sched.sh&lt;/string&gt;
  &lt;key&gt;StartCalendarInterval&lt;/key&gt;
     &lt;dict&gt;
     &lt;key&gt;Hour&lt;/key&gt;
     &lt;integer&gt;8&lt;/integer&gt;
     &lt;key&gt;Minute&lt;/key&gt;
     &lt;integer&gt;0&lt;/integer&gt;
     &lt;/dict&gt;
&lt;/dict&gt;
&lt;/plist&gt;


And here is the bash script 

sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install


The length of time to block the blacklist in SelfControl for can be set by doing

defaults write org.eyebeam.SelfControl "BlockDuration"=xxx


I think that's all the relevant information
You should be able to control this with two different launchd jobs.


one job to start daily at 8 am 
another job to unload the first at quitting time (8 pm)


If the application doesn't expect to be loaded/unloaded (like mongodb does if you install it from homebrew), then change the second script to call your "kill" script.


How do I create an AppleScript that will quit an application at a specific time and then put the computer to sleep?
Applescript app to shut down Mathematica at a specific time of day


I'm of the mind to just call /usr/bin/killall SelfControl if that works rather than mucking with wrapping a mode convoluted AppleScript example with /usr/bin/osascript like in the example here:

/usr/bin/osascript -e 'tell application "Mathematica" to quit'


This is far more robust than making a helper script that needs to stay running since launchd keeps track of the time that passes when powered off and/or sleeping and should fire things later (say 23:30) if you wake the Mac from sleep starting at 6 pm.

I use LaunchControl or Lingon app to manage my plist files - but you can hand roll them too like your question.

The second is shorter, so I've named it org.you.control.unload and it simply calls launchctl unload org.you.control.load at 20:00 and set the RunAtLoad to /false so it only triggers per the clock.

&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.you.control.unload&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;launchctl&lt;/string&gt;
        &lt;string&gt;unload&lt;/string&gt;
        &lt;string&gt;org.you.control.load&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Hour&lt;/key&gt;
        &lt;integer&gt;20&lt;/integer&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
    &lt;/dict&gt;
&lt;/dict&gt;


Just decide on the names you want: org.you.control.load or ** my.selfControlScheduler** are both fine, but pick an idiom and stick with it throughout.

Your startup plist looks fine but there could be permissions or other issues that a tool to debug things without needing a handy reference like http://launchd.info

Rather than script the opening of the app, just call /usr/bin/open -a SelfControl would be my suggestion if yours isn't working presently.

&lt;string&gt;org.you.control.load&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/usr/bin/open&lt;/string&gt;
    &lt;string&gt;-a&lt;/string&gt;
    &lt;string&gt;SelfControl&lt;/string&gt;
&lt;/array&gt;