Apple - Can launchd run programs more frequently than every 10 seconds?

There is no way to bypass or decrease the time limit.

Apple's documentation regarding Creating Launchd Jobs states the following:

Important If your daemon shuts down too quickly after being launched, launchd may think it has crashed. Daemons that continue this behavior may be suspended and not launched again when future requests arrive. To avoid this behavior, do not shut down for at least 10 seconds after launch.

Your program or script needs to keep running for at least 10 seconds. Consider implementing a loop to check for file modification dates in the last ten seconds, sleeping for ten seconds, and repeating.

Alternatively, you can watch specific files using the kqueue or FSEvents APIs. This StackOverflow question may be helpful, File-level filesystem change notification in Mac OS X.


You could keep your script running in a loop checking for modified files instead of quitting when it is done. Have it sleep for a few seconds after checking for the modified files. If it finds modified files, continue with the script. If not, sleep again.

Then have launchd start your script every x minutes just in case the previous run dies. Code the beginning of your script to check if another instance is already running and if so, quit itself.

Tags:

Macos

Launchd