How to get a launchd plist to diretly run a complex 1 line bash command?

Solution 1:

Yes. When setting up the ProgramArguments element, simply use bash as the first argument, -c as the second argument, then [your commands] (remembering to replace any XML entities, such as >, & and so on) as the third, like so:

<key>ProgramArguments</key>
<array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>ls -1 | grep *.txt | echo &gt; allTextFiles</string>
</array>

Replace the third element of the array with your actual command.