How to adjust what is displayed in the Login Items list for my launch daemon/agent in macOS?

505 Views Asked by At

My launch daemon (and the launch agent) are installed system-wide on macOS. I use the following plist file (say, for the daemon) that is placed into the following file /Library/LaunchDaemons/com.example.MyDaemon.plist:

<?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>MachServices</key>
    <dict>
        <key>com.example.MyDaemon.launch.agent</key>
        <true/>
    </dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.example.MyDaemon</string>
    <key>Program</key>
    <string>/Library/PrivilegedHelperTools/com.example/MyDaemon</string>
    <key>ProgramArguments</key>
    <array>
        <string>-d</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

When the plist above is installed, or when the user re-logs-in, the macOS shows this not-very-friendly popup:

enter image description here

And then if I go to Settings -> General -> Login Items, it is shown there as well:

enter image description here

I understand that this is shown for security reason. But I'm curious:

  1. Can I provide the name of my app that is shown? For now, I'm not even sure where the name is coming from. For instance, now the popup shows:

"MyDaemon" is an item that can run in the background. You can manage this in Login Items Settings

Can I change "MyDaemon" to some better description in that popup?

  1. The small text in the Login Items says:

Item from unidentified developer.

I noticed that other items don't have this message. What am I doing wrong?

  1. I also noticed that other items in the Login Items list don't invoke a popup, like my item. For instance, there's also Zoom which doesn't show that popup. What am I doing differently to have my item show that popup?
2

There are 2 best solutions below

4
pmdj On

1. Name (and icon) of the launch item

The usual way to get this is to use the Service Management APIs to install the daemon, so SMAppService or SMJobBless, depending on OS version. Then it inherits the icon and name from the app in which it's embedded.

You may also be able to achieve something similar by giving your daemon binary an Info.plist, for example by embedding it in the __info_plist __TEXT section of the binary or by placing it inside a bundle or turning it into an app bundle. Then set the CFBundleDisplayName, CFBundleName, or other likely-sounding keys and see if that changes the way it's displayed.

Here's some info on the embedded Info.plist, and here's info on how to compose an Info.plist file.

2. "Unidentified developer

The "unidentified developer" part is due to lack of (valid) codesigning. If your daemon binary is correctly signed with a Developer ID certificate and notarised (or distributed via the app store), either your app name (see above) or your developer account name will show up instead.

3. Popup

For instance, there's also Zoom which doesn't show that popup.

Zoom installs its helper via the System Management APIs, which require explicit authorisation when calling the API, perhaps it doesn't require double opt-in in that case?

0
dev_null On

So there is a new AssociatedBundleIdentifiers key which is either a string or a dictionary of strings in LaunchAgents/Daemons plist file. It works for applications. It doesn't (at least for the moment) for generic bundles like XPC or VST3 audio plug-ins. So if you don't have an application bundle and you do want a good-looking item in system preferences - create a fake one, with icon and name. An example of working plist file (with replaced identifiers and path for sure) is below

<?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>AssociatedBundleIdentifiers</key>
    <array>
        <string>com.yourcompany.your_fake_or_real_app_bundle_id</string>
    </array>
    <key>MachServices</key>
    <dict>
        <key>com.yourcompany.agent-xpc</key>
        <true/>
    </dict>
    <key>Label</key>
    <string>com.yourcompany.agent-xpc</string>
    <key>KeepAlive</key>
    <false/>
    <key>Program</key>
    <string>/PathTo/Your/AgentBinary</string>
</dict>
</plist>