Mac launchctl StartInterval not working

It looks like the Mac launchd launchctl StartInterval is broken in Mac OS X 10.6.x, at least the current version (10.6.7). When I run a Mac launchctl script like this, which used to work just fine:

<?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>com.valleyprogramming.pingdatabase</string>

  <key>ProgramArguments</key>
  <array>
     <string>/Users/Al/Projects/TestValleyProgramming/hit-vp-db.sh</string>
  </array>

  <key>OnDemand</key>
  <false/>

  <key>Nice</key>
  <integer>1</integer>

  <key>StartInterval</key>
  <integer>120</integer>

  <key>StandardErrorPath</key>
  <string>/Users/Al/Projects/TestValleyProgramming/stderr.db</string>

  <key>StandardOutPath</key>
  <string>/Users/Al/Projects/TestValleyProgramming/stdout.db</string>
</dict>
</plist>

the script insists on running every ten seconds. So last night I ended up hitting a website URL 4,500 times instead of the 450 I was planning on.

I first wrote about that launchctl plist file in my Mac OS X crontab launchctl launchd tutorial last year, when I tested it thoroughly.

Possible solution: Use the launchctl ThrottleInterval command to fix StartInterval

Since it appears that the OS X launchctl/launchd system is ignoring the StartInterval and just running commands every ten seconds (some sort of system default), the fix for this problem is to specify the launchctl ThrottleInterval. You can create a ThrottleInterval setting like this:

<key>ThrottleInterval</key>
<integer>120</integer>

In that case I'm telling the Mac launchd/launchctl system to run this command no more often than once every 120 seconds (two minutes).

I just learned about the StartInterval being broken on this Apple forum thread, where another launchd launchctl user reported the same ten-second problem I just managed to verify.

Another solution: OnDemand is deprecated and broken

I just read on another Apple forum page that the problem is the use of the OnDemand key in the code above. Sure enough, removing OnDemand from the plist file fixes the problem.

I don't think it's wrong to have used the OnDemand key, I just think that key is broken. Possibly what's going on here is that Apple deprecated the OnDemand key, and when they deprecate things, they don't give you much grace time. It's probably correct to use the KeepAlive key here instead of the OnDemand key, but alas, I'm out of time for today. (See the Apple launchd plist manual page for more information about the OnDemand and KeepAlive settings.)