Remove an Agent from launchd
The vast majority of Mac users won’t need to manually tweak launchd and launchctl, but there are times when you uninstall or stop using an app in Mac OS X and a service agent continues to needlessly load in launchd. This is annoying, but these rogue agents are easy to remove via the command line, so launch Terminal and away we go.
You’ll need to have some understanding and comfort of using the command line and Terminal to use this properly, making this ideal for more advanced users who have knowledge of launch daemons and how to track them down, which, sometimes, is just a matter of finding one in the Activity Monitor of Mac OS X, or by using the launchctl command we’ll discuss shortly. If you decide to reverse the modification, you can also load the service or daemon back into launchd using another command, which effectively undoes the initial removal step. Let’s get to it:
Removing Launch Agents & Services from launchd
Here is how to remove a service from launchd. Launch Terminal and then use the following syntax with the launchctl command:
launchctl remove name
For example, if I want to remove a service named “com.annoying.service” the syntax would be:
launchctl remove com.annoying.service
You may need to prefix the command with sudo in order to remove the service, in this case the command would be:
sudo launchctl remove com.annoying.service
With the sudo prefix you’ll have to enter an administrator password before the command will execute.
How to See What is Loaded in launhcd
You can also check what’s loaded into launchd by using the following command string:
This command lists all agents and jobs loaded into launchd, allowing you to easily manipulate the agents that are running. Because it dumps a ton of information onto the screen at once, you may want to pipe it through the more or less commands like so:
launchctl list |more
This lets you hit the return key to more slowly navigate through the list.
If you know generally the service you’re looking for, you can also use “grep” to find the precise agents service, let’s use ‘mdworker’ as an example::
launchctl list |grep mdworker
This would report back only the following launchagents:
- 0 com.apple.mdworker.sizing
- 0 com.apple.mdworker.single
- 0 com.apple.mdworker.shared
- 0 com.apple.mdworker.mail
- 0 com.apple.mdworker.lsb
- 0 com.apple.mdworker.isolation
- 0 com.apple.mdworker.bundles
- 0 com.apple.mdworker.32bit
For some services, dumping the list may also show the PID (process ID) of the active service as well.
Loading an Agent Back into launchd
If you decide you want to reenable and reload a service back into launchd, use the ‘load’ flag like so:
launchctl load com.example.service.to.load
Some agents will load instantly without issue. For others, you may need to reboot the Mac before the loaded service will function as intended again, though sometimes logging out and back in is sufficient as well.