Category filter
Script to launch apps automatically while logging in to Mac
There might be specific apps that users launch every time they turn on their devices. It’ll be convenient to have these apps automatically opened as soon as the user logs in to the device. This can be done by specifying the required apps in the following script and running it from the Terminal app.
With Hexnode, you can deploy this script to your entire Mac fleet using the Execute Custom Script action.
Scripting Language – Bash
File extension – .sh
Launch Apps Automatically
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/bin/bash touch '/Library/LaunchAgents/com.app_name.plist' cat > /Library/LaunchAgents/com.app_name.plist <<EOF <?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>KeepAlive</key> <false/> <key>Label</key> <string>com.app_name.plist</string> <key>Program</key> <string>/System/Applications/app_name.app/Contents/MacOS/app_name</string> <key>RunAtLoad</key> <true/> </dict> </plist> |
Executing the above script on your Mac will create a launch agent for the specified app in /Library/LaunchAgents and runs for every user account upon logging in.
Replace app_name in the script with the name of the application you require to launch automatically on logging in to the Mac and specify the full path of the executable file for the application under the
For example, the following script will automatically launch the ‘Messages’ application when a user logs in to the Mac:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/bin/bash touch '/Library/LaunchAgents/com.Messages.plist' cat > /Library/LaunchAgents/com.Messages.plist <<EOF <?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>KeepAlive</key> <false/> <key>Label</key> <string>com.Messages.plist</string> <key>Program</key> <string>/System/Applications/Messages.app/Contents/MacOS/Messages</string> <key>RunAtLoad</key> <true/> </dict> </plist> |