1

I know I can use "Service Management" (SMAppManager) for the current user [or do the equivalent action via setup], but it only registers at login for the current user, but I need my app to register at login for the current user and for all other users.

do {
    try SMAppService.mainApp.register()
}
catch {
    print(error)
}

I know that you can use "RunAlLoad" in the launchd config, but it doesn't work quite the way I want it to because it actually starts when the program is loaded when loaded via launchctl or only after a reboot.

<?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="2.0">
<dict>  
    <key>Label</key>
    <string>com.companyname.application</string>
    
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/application</string>
    </array>

    <key>RunAtLoad</key>
    <true/>

</dict>
</plist>

I also tried using the "OnDemand" option with the value "false", but then the application just starts all time:

<?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="2.0">
<dict>  
    <key>Label</key>
    <string>com.companyname.application</string>
    
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/application</string>
    </array>

    <key>OnDemand</key>
    <false/>

</dict>
</plist>

Which launchd config file can be used for this or how can I do it with "Service Management" ?

1 Answer 1

1

User Specific

Apple's Service Management API is limited to the scope of a single user. From macOS 13, this is Apple's recommended method for managing service processes.

It is possible to infer Apple's opinion on computer-wide third party processes from this API design choice.

Computer Wide

For a process to be launched for all users, the launchd file needs to be placed in one of the computer wide folders:

  • /Library/LaunchAgents
  • /Library/LaunchDaemons

See man launchd for a description of each folder's scope and available options:

/Library/LaunchAgents

Per-user agents provided by the administrator.

/Library/LaunchDaemons

System-wide daemons provided by the administrator.

1
  • The difference between launch agents and daemons is that launch agents run inside user sessions, while daemons run in system context independent of who is or isn't logged in. It sounds like you want a launch agent here. Sep 10, 2023 at 2:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .