Running a shell script on login in macOS Sequoia (or any recent macOS version) is certainly doable, and there are a few clean ways to go about it depending on what you need—whether it’s for just your user session or system-wide. The most straightforward and reliable method is using LaunchAgents, which is the Apple-sanctioned way to run scripts or executables at login for a specific user.
Here's an example which should get you started on developing your own for your specific needs:
- You, of course, would start with a shell script. In this example, we will create one called: hello.sh
- Its contents would be something like: echo "Hello, World!" >> ~/Documents/hello_output.txt
- Save it somewhere safe, like: ~/Scripts/hello.sh
- Don’t forget to make it executable: chmod +x ~/Scripts/hello.sh
- Next, you will want to create a LaunchAgent plist file in : ~/Library/LaunchAgents/
- Create a file like `com.yourname.helloscript.plist` with the following content:
<?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.yourname.helloscript</string>
<key>ProgramArguments</key>
<array>
<string>/Users/yourusername/Scripts/hello.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/helloscript.out</string>
<key>StandardErrorPath</key>
<string>/tmp/helloscript.err</string>
</dict>
</plist>
Replace `yourusername` with your actual macOS short username.
- Next, you will want to load the LaunchAgent, To do so, open the Terminal app, and run:
- launchctl load ~/Library/LaunchAgents/com.yourname.helloscript.plist
This will set it up to run every time you log in.
As far as learning guides ...
If you like to start with the *straight-from-Apple* material, three that come to mind are:
- Shell Scripting Primer on the Apple Developer site
- Intro to Shell Scripts article in Apple Support, and
- The launchd script-management guide for learning how to make your scripts run on login, schedule, or system-boot.
For deeper dives—and tips that feel more “Mac admin” than “Unix 101”— I suggest Armin Briegel’s Scripting OS X blog. In addition, you may like: Kandji’s Introduction to Mac Shell Scripts.