Launch agent loading question I have the following launch agent that runs on OS X and runs the below script to delete an app when a user downloads an OS upgrade from the App store. It then displays a message to a user after it is deleted.

#!/bin/bash

Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)    

if [[ $Version -ge 11 ]]
then  
    launchctl unload /Library/LaunchAgents/net.company_name.blocksierra.plist
    rm -f /Library/LaunchAgents/net.company_name.blocksierra.plist
    rm -f /usr/local/bin/blocksierra.sh
exit 0

else
    rm -rf /Applications/Install\ macOS\ Sierra\ Public\ Beta.app/
    osascript -e 'display dialog "macOS sierra is not allowed on computers at this time." with title "Technology Notice" buttons {"OK"} default button "OK" giving up after 30'
fi


I am now going to package it and then deploy it to all of our Mac machines. My question is what do I add to the script to get the package to auto "load" the launchagent automatically once the package is installed?

So in other words how do I incorporate this command?

sudo launchctl load /Library/LaunchAgents/net.company_name.blocksierra.plist


Here is the plist

&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;net.company_name.blocksierra&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/usr/local/bin/blocksierra.sh&lt;/string&gt;
&lt;/array&gt;
&lt;key&gt;KeepAlive&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;PathState&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;/Applications/Install macOS Sierra Public Beta.app/&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/dict&gt;
&lt;key&gt;OnDemand&lt;/key&gt;
&lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;
All jobs related to items installed by packages (i.e. a pkg installer) are done with preflight or postflight scripts which are included in the package. 

A preflight script may check if a needed folder exists and if its permissions are set properly. A postflight script may load launch agents and daemons installed by the pkg installer and set their owners and permissions.

In your case you would use a postflight script like this one:

#!/bin/bash

sudo /bin/launchctl load /Library/LaunchAgents/net.company_name.blocksierra.plist




BTW: Using if [[ $Version -ge 11 ]] will unload and delete the launch agent when El Capitan is installed. You may have to change this to 12.