Search code examples
phpmacosintervalslaunchd

OSX launchd - running script in the Background Session ignores StartInterval


Community!

I am trying to execute a simple script every 5 minutes on my OSX 10.7.4. It should run no matter a user is logged into the machine or not (aka in the background session)

Thus I created I com.me.script.plist in /System/Library/LaunchDaemons/ and loaded it via: launchctl -S background ./com.me.script.plist and started it via: launchchctl start com.me.script

It runs fine the first time. But it never runs again after my set interval of 300seconds!

Do you guys have any advice as to why that could be? If I run it in the Aqua Session it works perfectly, however, that means it'll only run if a user is logged in. However, I'd really need it to start running before that... and continue to do so no matter if a user logs in/out or another user logs in/out.

Here's my plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>LimitLoadToSessionType</key>
        <string>Background</string>
        <key>Label</key>
        <string>com.me.script</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/bin/php</string>
            <string>/Sites/script/notifier.php</string>
        </array>
        <key>StartInterval</key>
        <integer>900</integer>
    </dict>
</plist>

Solution

  • I found my own mistake... StartInterval should be 300 and not 900 if I expect it to run every 5min. sorry, stupid.