In my understanding launchd
has a single domain, the system
domain which itself has two subdomain types user
and pid
.
com.apple.xpc.launchd.domain.system
.
com.apple.xpc.launchd.domain.user.<uid>
com.apple.xpc.launchd.domain.pid.<pid>
:
To see all subdomains of the system domain:1
$ launchctl print system | awk '/^\t*subdomains/,/^\t*}/'
subdomains = {
com.apple.xpc.launchd.domain.pid.systemstats.1142
com.apple.xpc.launchd.domain.pid.softwareupdated.738
com.apple.xpc.launchd.domain.user.501
...
}
My further interpretation is that if a user account is a regular user account and the user is currently logged into the graphical user interface then the user domain will have a user login subdomain for that user account.
$ launchctl print user/$(id -u) | awk '/^\tsubdomains/,/^\t}/'
subdomains = {
com.apple.xpc.launchd.user.domain.501.104157.Aqua
}
My further interpretation is that if that subdomain exists then login/<asid>
and gui/<uid>
can be used to access the services within that subdomain.
Either using the UID:
$ launchctl print user/$(id -u) | awk '/^\tservices/,/^\t}/'
services = {
61949 (pe) com.apple.tonelibraryd
0 - com.apple.accounts.dom
421 - com.apple.distnoted.xpc.agent
...
}
Or alternatively the ASID (audit session identifier):
$ ASID=$(id -A | awk -F"=" '/asid/ {print $2}')
$ launchctl print login/$ASID | awk '/^\tservices/,/^\t}/'
There doesn't seems to be an official way to retrieve the domains that a service is currently registered in, but using launchctl dumpstate
could be an approach.2
$ launchctl dumpstate | awk '/^com.apple.AVKit.OutputDeviceMenuService/,/^}/' | grep domain
domain = com.apple.xpc.launchd.domain.pid.photoanalysisd.79837
domain = com.apple.xpc.launchd.domain.pid.Spotlight.79609
domain = com.apple.xpc.launchd.domain.pid.Finder.79572
Wrapping that into a Bash function and adding it to ~/.bashrc
:
function launchctl_domains () {
SERVICE="$1"
launchctl dumpstate | awk "/^$SERVICE/,/^}/" | awk -F"=" '/domain/ {print $2}' | awk '{$1=$1;print}'
}
export -f launchctl_domains
A service in multiple PID domains:
$ launchctl_domains com.apple.AVKit.OutputDeviceMenuService
com.apple.xpc.launchd.domain.pid.photoanalysisd.79837
com.apple.xpc.launchd.domain.pid.Spotlight.79609
com.apple.xpc.launchd.domain.pid.Finder.79572
A service in multiple user domains:
$ launchctl_domains com.apple.tonelibraryd
com.apple.xpc.launchd.domain.user.501
com.apple.xpc.launchd.domain.user.0
A service in a login user/GUI domain:
$ launchctl_domains com.apple.accountsd
com.apple.xpc.launchd.user.domain.501.104157.Aqua
1. Be aware that parsing the output of launchctl print
is strongly discouraged in the man page of launchctl
2. Documented in launchctl help
, it appears that the output is truncated after 20 MB
Everything tested on macOS Catalina 10.15.7
I'm aware that the question was asked some time ago, but hopefully it can shed some light on the topic for others.