MacOS – launchd seems ignore StartCalendarInterval on Yosemite

homebrewlaunchctllaunchdmacos

I tried to update Homebrew on time with launchd. My plist file is presented here:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>ms.liu.homebrew.update</string>
  <key>UserName</key>
  <string>LiuMS</string>
  <key>ProcessType</key>
  <string>Background</string>
  <key>EnvironmentVariables</key>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/brew</string>
    <string>update</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key>
    <integer>20</integer>
    <key>Minute</key>
    <integer>0</integer>
  </dict>
  <key>StandardOutPath</key>
  <string>/usr/local/logs/ms.liu.homebrew.update.out</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/logs/ms.liu.homebrew.update.err</string>
</dict>
</plist>

It does work somehow: I can execute launchctl start ms.liu.homebrew.update manually to update my Homebrew. However, launchd doesn't execute this service periodically: last changes to the file which stdout redirects to is two days ago.

I tried to get info about this service but got nothing:

> launchctl print user/%MyPID%/ms.liu.homebrew.update`` 
Could not find service "ms.liu.homebrew.update" in domain for uid: %MyPID%

It looks like I haven't successfully loaded my service. How? I used launchctl load but it seems that it has been deprecated. Man page recommends bootstrap instead:

> launchctl bootstrap user/%MyPID% %Path-to-plist%
> %Path-to-plist%: Service cannot load in requested session

What should I do? How to properly use launchctl bootstrap and launchctl print?

I am running OS X Yosemite GM Candidate 1 on MacBookPro with Retina display (2013).

Best Answer

I’m only just starting to work this stuff out, so this answer is tentative – but I hope it’s more helpful than no answer at all. (I would have left it as a comment if I had enough rep.)

Is this plist in your ~/Library/LaunchAgents directory? It seems that these are bootstrapped into your gui domain, not your user domain. So you can do:

launchctl print gui/%UID%/ms.liu.homebrew.update

and it should work. (Does it?)

Presumably the reason you can’t bootstrap it into the user domain is that it’s already bootstrapped into the gui domain.

Related Question