How to run multiple commands on reboot using launchctl/plist? In OS X, you can write a plist file in ~/Library/LaunchAgents/ (or something similar, depending on what permissions/users you like it to be operated on), and load it using launchctl to make it function on reboot. However, is it possible to define multiple commands in the plist file, and if that's the case, how can I define it?

For example, suppose that I want to run a series of Python programs, such as:

python first_script.py


And then I want to run the script after the first script is done (so I cannot just define those two scripts in two different plist files, since it doesn't guarantee which one to be executed first), I want to run this script:

python second_script.py


I use OS X Mavericks 10.9.2.

bonus

This is not what I want to do right now and comes from nothing but curiosity, but is it also possible to execute the second program depending upon the result of the first program? So for example:

python first_script.py


And if this script succeeds:

python second_script.py --result true


And if it fails:

python second_script.py --result false --reason XXX
Run a shell command that starts the other commands:

&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;some.label&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;bash&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;python first_script.py;python second_script.py&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Or change the ProgramArguments key to

&lt;key&gt;Program&lt;/key&gt;
&lt;string&gt;/path/to/script&lt;/string&gt;


and use a script like this:

#!/bin/bash

output=$(python first_script.py 2&gt;&amp;1)
if [[ $? = 0 ]]; then
  python second_script.py --result true
else
  python second_script.py --result --false --reason "$output"
fi