In daily Mac usage, startup items significantly impact both system boot time and overall performance. Excessive or unnecessary startup items can extend boot time and consume system resources, leading to slower performance. This guide will detail how to view, add, and remove Mac startup items through the command line, helping you optimize your system's startup behavior and enhance your user experience.
What are Startup Items?
Startup Items are applications, services, or scripts that automatically run when your system starts or when a user logs in. These items can be implemented through various mechanisms, including Launch Agents, Launch Daemons, Login Items, and Cron Jobs. Managing these startup items effectively can significantly improve your Mac's boot speed and operational efficiency.
Viewing Mac Startup Items
Understanding current startup items is the first step in management and optimization. Here are several common methods to view different types of startup items via command line.
Using launchctl
to View Launch Agents and Launch Daemons
Launch Agents and Launch Daemons are the primary mechanisms for managing background services and application startup items in macOS.
- View all loaded Launch Agents and Launch Daemons:
launchctl list
This command lists all currently loaded Launch Agents and Launch Daemons, including both system-level and user-level items.
- View system-level Launch Daemons:
ls /Library/LaunchDaemons
- View system-level Launch Agents:
ls /Library/LaunchAgents
- View user-level Launch Agents:
ls ~/Library/LaunchAgents
Viewing Login Items
Login Items are applications that automatically start when a user logs in. You can view the current user's login items using:
osascript -e 'tell application "System Events" to get the name of every login item'
Sample output:
Perplexity, Loop, Quark Drive, Raycast, PasteNow, ZeroTier, Baidu Drive, Yoink, NeatDownloadManager, ApifoxAppAgent, Aliyun Drive, FigmaAgent, Shottr
Checking StartupItems Folder
While the /Library/StartupItems
directory is less commonly used in newer macOS versions, legacy startup items might still exist:
ls /Library/StartupItems
Viewing Cron Jobs
Cron Jobs are scheduled tasks that can be used for startup scripts:
- View current user's Cron Jobs:
crontab -l
- View system-wide Cron Jobs:
sudo cat /etc/crontab
Using systemsetup
to View System Startup Settings
The systemsetup
tool configures system settings and can view startup-related information:
- View auto-login user:
systemsetup -getautoLoginUser
Managing Login Items: Adding and Removing
After reviewing current login items, you might want to add or remove certain items to optimize system performance. Here's how to manage login items via command line.
Removing Specific Login Items
To remove a specific login item (e.g., "Shottr"), use:
osascript -e 'tell application "System Events" to delete login item "Shottr"'
Note: The login item name must exactly match the system name, including case and spaces.
Batch Removing Multiple Login Items
To remove multiple login items, you can either execute osascript
commands sequentially or create a script. For example, to remove "Perplexity" and "Loop":
osascript -e 'tell application "System Events" to delete login item "Perplexity"'
osascript -e 'tell application "System Events" to delete login item "Loop"'
Adding New Login Items
While macOS doesn't provide direct command-line tools for adding login items, you can use osascript
. For example, to add "Visual Studio Code":
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/Visual Studio Code.app", hidden:false}'
Parameters:
path
: Full path to the applicationhidden
: Whether to hide the application window at startup (true
orfalse
)
Scripted Login Item Management
To simplify operations, you can create a script file with multiple commands. Here's how:
- Create a removal script:
#!/bin/bash
# Remove specified login items
osascript -e 'tell application "System Events" to delete login item "Perplexity"'
osascript -e 'tell application "System Events" to delete login item "Loop"'
osascript -e 'tell application "System Events" to delete login item "Quark Drive"'
osascript -e 'tell application "System Events" to delete login item "Baidu Drive"'
osascript -e 'tell application "System Events" to delete login item "ApifoxAppAgent"'
osascript -e 'tell application "System Events" to delete login item "Aliyun Drive"'
osascript -e 'tell application "System Events" to delete login item "FigmaAgent"'
echo "Specified login items have been removed."
- Make the script executable:
chmod +x remove_login_items.sh
- Run the script:
./remove_login_items.sh
- Verify the results:
osascript -e 'tell application "System Events" to get the name of every login item'
Expected output should no longer include removed items:
Raycast, PasteNow, ZeroTier, Yoink, NeatDownloadManager, Shottr
By following these steps, you can effectively manage your Mac's startup items and optimize system performance. If you encounter any issues during the process, feel free to reach out for assistance!s