This article shows how to create a script that runs when a user logs and deploy it using Smart Software.
Launch Daemon or Launch Agent
To set up a script to run at login, you will need to create either a Launch Daemon or a Launch Agent. A Launch Daemon will run the script as root, while a Launch Agent will run as the logged-in user. This is determined on which folder the settings defined by the property list, also known as a .plist, is copied to:
/Library/LaunchDaemons = run as root /Library/LaunchAgents = run as logged-in user
Creating the script and plist
You will need two files:
- The previously mentioned .plist
- The script that runs at login
Create the plist
To create the .plist copy this text and save it as a .plist.
Note: Make sure the Program key's value is the path to the script.
<?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>
The Installation Script
Addigy's Smart Software supports a custom installation script. This script will:
- Change the permission of your login script
- Move the file(s) to either /Library/LaunchDaemons or /Library/LaunchAgents
- And finally, load the plist
Note: Replace Name_of_Script, Name_of_Property_List.plist, and which folder to move the .plist to:
#Change permission of the script chmod +x ./Name_of_Script.sh #Move the files to their appropriate directory cp Name_of_Script.sh /Library/Addigy/ cp Name_of_Property_List.plist /Library/LaunchAgents/ #Load the .plist sudo launchctl load -w /Library/LaunchAgents/Name_of_Property_List.plist
Your Smart Software is ready to save and deploy.
As always, we recommend assigning it to a policy with only test Macs before deploying it to a larger group.