MacOS – the difference between a `service-name` and a `service-target`

command linelaunchdmacos

Consider the following commands

# launchctl stop 
Usage: launchctl stop <service-name>
# launchctl stop com.apple.SomeService
# launchctl disable com.apple.SomeService
Usage: launchctl disable <service-target>

What is the difference between a service-target and a service-name? How can I learn a service-target of a service from it's service-name?

Best Answer

A service target is a service name plus a target domain, which describes the context in which the service runs, e.g. whether it runs at system startup or when a particular user logs in etc.

The launchctl(1) manpage describes 6 ways of forming a service target from a service name. If you want to disable a service that runs at startup, you probably want one of these three depending on whether it's a service that runs at system startup or when you log in:

system/[service-name]
    Targets the system domain or a service within the system domain. The system
    domain manages the root Mach bootstrap and is considered a privileged execu-
    tion context. Anyone may read or query the system domain, but root privi-
    leges are required to make modifications.

user/<uid>/[service-name]
    Targets the user domain for the given UID or a service within that domain. A
    user domain may exist independently of a logged-in user. User domains do not
    exist on iOS.

gui/<uid>/[service-name]
    Another form of the login specifier. Rather than specifying a user-login
    domain by its ASID, this specifier targets the domain based on which user it
    is associated with and is generally more convenient.

You can find out the uid number for your user account like this:

$ id -u [your-username]
502