How to make ''sudo launchctl limit' change permanent? I have a background job that failed due to too many open files error.

To fix it, I  have to kill the job, then run the following

sudo launchctl limit maxfiles 10240 10240


before restarting it.

Is there any way I can make the launchctl limit maxfiles change permanent?
You can create a launch daemon to run that command on every startup. Create /Library/LaunchDaemons/private.maxfiles.plist with the following contents:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//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;private.maxfiles&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;launchctl&lt;/string&gt;
            &lt;string&gt;limit&lt;/string&gt;
            &lt;string&gt;maxfiles&lt;/string&gt;
            &lt;string&gt;10240&lt;/string&gt;
            &lt;string&gt;10240&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;