Wesley de Groot's Blog
Controllig login and background items

Back

In This post, we'll take a look at how to control login and background items on macOS.
When you start your Mac, you may have noticed that some apps or items automatically start up or appear in the background. This can be useful for apps that you use frequently, but it can also slow down your Mac or clutter your desktop.

Difference between Login Items and Background Items

  • Login Items: These are apps or items that automatically start up when you log in to your Mac. They can be useful for apps that you use frequently, such as messaging apps, email clients, or productivity tools.
  • Background Items: These are apps or items that run in the background when you start your Mac. They can be useful for apps that need to perform tasks in the background, such as cloud storage services, backup utilities, or system utilities.

* You can add or remove login items in the Users & Groups preferences pane in System Preferences. You can also use the sfltool command-line tool to list, add, remove, or reset login items, this is the tool we will use in this post.

How to List Login Items

This command will list all the login items that are set to start up when you log in to your Mac.

  • Open terminal
  • Type sudo sfltool dumpbtm

* Tip: Export the output to a text file, so you can read the values if you have resetted the login items.

Dump Login Items to a Text File

This can be useful if you want to save the list of login items to a text file for reference before making any changes.

  • Open terminal
  • Type sudo sfltool dumpbtm > ~/Desktop.login_items.txt
  • Open the file login_items.txt on your desktop to see the list of login items.

How to Add Login Items

Adding login items to start those apps when you log in to your Mac.

  • Open terminal
  • Type sudo sfltool add --label "App Name" -a "/Applications/AppName.app"

How to Remove Login Items

Removing login items to stop those apps from starting when you log in to your Mac.

  • Open terminal
  • Type sudo sfltool remove --label "App Name"

Reset Login Items

If you see a whole bunch of login items that you don't recognize or can't remove, you can reset the login items list to the default settings.

  • Open terminal
  • Type sudo sfltool reset

launchctl Command (Background Items)

You can use the launchctl command-line tool to manage background items on macOS. Here are some useful commands:

  • launchctl list - List all background items.
  • launchctl start <label> - Start a background item.
  • launchctl stop <label> - Stop a background item.
  • launchctl remove <label> - Remove a background item.
  • launchctl load <path> - Load a background item from a property list file.
  • launchctl unload <path> - Unload a background item from a property list file.
  • launchctl print <label> - Print the properties of a background item.

Items loaded by launchctl are usually controlled by Property Lists installed in the ~/Library/LaunchAgents folder.

Example Launch Agent.

Here is an example of a Launc Agent file that imports screenshots i've taken into my photo library using Apples Shortcuts Application with this shortcut.

<?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>nl.wesleydegroot.ImportScreenshotsShortcut</string>
     <key>ProgramArguments</key>
     <array>
        <string>/usr/bin/shortcuts</string>
        <string>run</string>
        <string>Import Screenshots</string>
     </array>
     <key>RunAtLoad</key>
     <true />
     <key>StandardErrorPath</key>
     <string>/dev/null</string>
     <key>StandardOutPath</key>
     <string>/dev/null</string>
     <key>StartInterval</key>
     <integer>30</integer>
  </dict>
</plist>

This file is saved as ~/Library/LaunchAgents/nl.wesleydegroot.ImportScreenshotsShortcut.plist and is loaded using launchctl load ~/Library/LaunchAgents/nl.wesleydegroot.ImportScreenshotsShortcut.plist.

Explanation of the keys in the Property List:

  • Label: A unique identifier for the item.
  • ProgramArguments: The command to run when the item needs to be started.
  • RunAtLoad: Whether the item should be started when the system starts.
  • StandardErrorPath: The file to write standard error output to. (/dev/null means discard the output).
  • StandardOutPath: The file to write standard output to. (/dev/null means discard the output).
  • StartInterval: The interval at which the item should be started (in seconds).

Extra facts

  • Background items are mostly controlled using Property Lists traditionally installed in LaunchAgents and LaunchDaemons folders.
  • You can use the launchctl command-line tool to manage background items.
  • You can use the Activity Monitor app to see which apps are running in the background and how much system resources they are using.

Read more

Share


Share Mastodon Twitter LinkedIn Facebook
x-twitter mastodon github linkedin discord threads instagram whatsapp bluesky square-rss sitemap