You start your Mac. It boots up smoothly. But what if you could add your own magic to this process? Imagine launching your favorite apps automatically, setting up your workspace, or even running scripts as soon as your desktop appears.
Well, guess what? You can! And it’s actually easier than you’d think. One of the coolest ways to take control of your Mac’s startup sequence is by using a neat little script called Userinit.sh. This guide will walk you through how to use it step-by-step.
What is Userinit.sh?
Userinit.sh is just a simple shell script. But when you place it in the right folder, macOS will run it every single time you log in. That makes it a fantastic way to customize your startup.
You can think of it like your Mac’s “morning routine.” It brushes its teeth (system tasks), stretches (loads the desktop), and then—because of you—makes coffee (runs your apps, opens folders, executes scripts… anything you want!).
Where to Put Userinit.sh
For this to work, you need to place Userinit.sh in the correct location. Here’s how to do it:
- Open the Terminal. You can find it in Applications > Utilities.
- Navigate to your user’s LaunchAgents folder:
cd ~/Library/LaunchAgents - If this folder doesn’t exist, create it:
mkdir -p ~/Library/LaunchAgents
We’ll come back to this folder soon to create a Launch Agent that points to your script. But first, let’s create the script itself.
Creating Your Own Userinit.sh
Now let’s make your own startup script!
- In Terminal, go to your user home folder:
cd ~ - Create and open a file called Userinit.sh:
nano Userinit.sh - Now type your startup commands. For example:
#!/bin/bash
# Open Safari
open -a Safari
# Open a folder
open ~/Documents/Work
# Run a custom script
bash ~/myscripts/start-workflow.sh
Make sure to make your script executable:
chmod +x ~/Userinit.sh
Connecting It with Launch Agents
A Launch Agent is a small .plist file that tells macOS what to start and when. You’ll create one to trigger your Userinit.sh at login.
- Back in the Terminal, go to
~/Library/LaunchAgents - Create a new file:
nano com.user.userinit.plist - Paste this template, updating the script path if needed:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.userinit</string>
<key>ProgramArguments</key>
<array>
<string>/Users/yourusername/Userinit.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Don’t forget to replace yourusername with your actual Mac username!
Now load the Launch Agent:
launchctl load ~/Library/LaunchAgents/com.user.userinit.plist
That’s it! From now on, every time you log in, your script will run automatically.
Fun Ideas for Your Userinit
Not sure what to include in your startup script? Here are some fun and useful ideas:
- Open work apps: Slack, Outlook, Chrome, etc.
- Launch your journal app to start your day mindfully.
- Connect to a VPN or remote server.
- Play your morning playlist:
afplay ~/Music/morning-tune.mp3
Basically, anything you can do in Terminal, you can automate in your script!
Advanced Tips (Still Simple!)
Want to level up? Here are some neat extras you can add:
1. Add a Delay
Sometimes it’s helpful to wait a few seconds before launching everything at once. This prevents overload right after login.
sleep 5
2. Redirect Output to a Log File
This helps you debug if something goes wrong.
/path/to/command >> ~/startup.log 2>&1
3. Use Conditional Logic
Only run certain commands on weekdays:
if [[ $(date +%u) -lt 6 ]]; then
open -a "Slack"
fi
Troubleshooting
Isn’t working? Don’t worry. Here are quick fixes:
- Double-check file permissions: Run
chmod +x ~/Userinit.sh - Make sure paths are correct: Use full paths, not just relative paths.
- View logs: Check with
cat ~/startup.log, if you added logging. - Unload and Reload Launch Agent:
launchctl unload ~/Library/LaunchAgents/com.user.userinit.plist
launchctl load ~/Library/LaunchAgents/com.user.userinit.plist
Why Use This Instead of Login Items?
Good question! You can always set apps to open using System Preferences → Users & Groups → Login Items. But this gives you more power.
With Userinit.sh, you can:
- Run scripts, not just open apps
- Add custom logic
- Control the sequence of actions
- Log results of commands
It’s like turning your Mac into your helpful assistant—ready to prep your digital life just the way you like it.
Backing It Up
If you rely on your Userinit setup, back it up! Copy your script and LaunchAgent plist files to a cloud folder or external drive. That way, you’re always ready to restore your cozy setup even after a clean install.
Wrap-Up: You’re Now a Startup Wizard!
You did it. You’ve demystified part of macOS that most users never touch. And made it simple and fun. Give your Mac a personal touch—and some seriously cool automation at the same time.
The best part? You can keep editing and growing your Userinit.sh any time. Treat it like a living document that adapts as your needs change. Your Mac will thank you.