You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS中SMAppService登录项显示App名称而非CFBundleDisplayName求助

解决LaunchAgent登录项显示主应用CFBundleDisplayName的问题
  • 直接在LaunchAgent的plist文件中添加CFBundleDisplayName键,指定为你期望的显示名称"ABC",这是最可靠的解决方式。
  • 保留AssociatedBundleIdentifiers关联主应用Bundle ID(com.example.X),同时确保LaunchAgent的Label与主应用Bundle ID一致。

具体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>Label</key>
    <string>com.example.X</string>
    <key>ProgramArguments</key>
    <array>
        <string>$(SRCROOT)/X.app/Contents/MacOS/YourAgentExecutable</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>AssociatedBundleIdentifiers</key>
    <array>
        <string>com.example.X</string>
    </array>
    <!-- 显式设置登录项显示名称 -->
    <key>CFBundleDisplayName</key>
    <string>ABC</string>
</dict>
</plist>

原因说明

SMAppService在展示登录项名称时,优先读取LaunchAgent自身plist的CFBundleDisplayName。即使你设置了AssociatedBundleIdentifiers关联主应用,系统在部分macOS版本(如Ventura及更早)中,不会自动拉取主应用的CFBundleDisplayName到登录项界面,这属于框架的已知行为限制。

额外检查点

确保你的SMAppService注册代码正确指定了Agent类型,示例代码如下:

let agentService = SMAppService.agent(plistName: "com.example.X.plist")
do {
    try agentService.register()
} catch {
    print("LaunchAgent注册失败: \(error.localizedDescription)")
}

内容的提问来源于stack exchange,提问作者Aashish Bhatia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 08:42:40