LaunchDaemons and LaunchAgents allow you to run scripts automatically at system startup or user login on managed Macs. This article walks through how to create the required files and deploy them using Addigy's Smart Software.
Overview
macOS uses a system called launchd to run background processes and scripts automatically. By creating a property list (.plist) and pairing it with a script, you can trigger automated actions on your devices — such as setting configurations, running maintenance tasks, or enforcing settings at login.
The key difference between the two types:
-
LaunchDaemon — Runs as
root. Use this for system-level tasks that don't require a logged-in user. - LaunchAgent — Runs as the logged-in user. Use this for tasks that should execute in the context of a specific user session.
Which type you create is determined by where the .plist file is placed on the device:
-
/Library/LaunchDaemons→ runs as root (LaunchDaemon) -
/Library/LaunchAgents→ runs as the logged-in user (LaunchAgent)
Step 1: Create Your Script
Write the shell script you want to run at launch or login. The script content is entirely up to you — it can run any command or series of commands appropriate for your use case.
Important: Test your script manually on a Mac before packaging it for deployment. A script that fails silently can be difficult to troubleshoot after deployment.
Step 2: Create the .plist File
The .plist file tells macOS how and when to run your script. Copy the template below and save it as a .plist file, updating the values to match your script's name and path.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.app</string>
<key>Program</key>
<string>/Library/Addigy/Name_of_Script.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>Key values to update:
-
Label — A unique identifier for this job (e.g.,
com.yourcompany.scriptname) - Program — The full path to your script as it will exist on the device
Step 3: Create the Smart Software Installation Script
Addigy's Smart Software supports a custom installation script that runs during deployment. This script handles three things: setting the correct file permissions, placing your files in the right directories, and loading the .plist with launchctl.
Create a new Smart Software item and upload your .plist file and .sh script as Installation Files.
Copy the script below to use as the Installation Command and replace:
-
Your Smart Software Item (1.0)with the name and version of your Smart Software item -
Name_of_Script.shwith the name of your .sh script -
Name_of_Property_List.plistwith the name of your .plist file
Update the target directory to /Library/LaunchDaemons or /Library/LaunchAgents depending on which type you're creating.
# Set execute permission on the script chmod +x "/Library/Addigy/ansible/packages/Your Smart Software Item (1.0)/Name_of_Script.sh" # Copy files to their target directories cp "/Library/Addigy/ansible/packages/Your Smart Software Item (1.0)/Name_of_Script.sh" /Library/Addigy/ cp "/Library/Addigy/ansible/packages/Your Smart Software Item (1.0)/Name_of_Property_List.plist" /Library/LaunchAgents/ # Load the plist to activate the LaunchAgent/LaunchDaemon sudo launchctl load -w /Library/LaunchAgents/Name_of_Property_List.plist
Finally, save the Smart Software item and add it to a policy for deployment.
Best practice: Before rolling out to your full device fleet, assign the Smart Software item to a policy containing only test Macs. Verify the script runs as expected before broader deployment.