简体   繁体   English

在启动时从 macOS 菜单栏隐藏应用程序图标

[英]Hide app icon from macOS menubar on launch

I'm making a macOS MenuBar app only, so how would you hide the App's Icon from the macOS dock when it's launched?我只制作一个 macOS MenuBar 应用程序,那么当应用程序启动时,您将如何从 macOS dock 隐藏该应用程序的图标?

I haven't seen anywhere where this is explain nor found any SwiftUI APIS/interactions with the AppDelegate.我没有看到任何地方对此进行解释,也没有找到任何 SwiftUI APIS/与 AppDelegate 的交互。

You need to set the following property in your Info.plist Application is agent (UIElement) to YES您需要在 Info.plist Application is agent (UIElement)中将以下属性设置为YES

You can find it in the documentation here .您可以在此处的文档中找到它。

Or you can manually edit the Info.plist and add the following key:或者您可以手动编辑 Info.plist 并添加以下键:

<key>LSUIElement</key>
<true/>

You can read about it here你可以在这里阅读

LSUIElement (Boolean - macOS) specifies whether the app runs as an agent app. LSUIElement(布尔值 - macOS)指定应用程序是否作为代理应用程序运行。 If this key is set to YES, Launch Services runs the app as an agent app.如果此键设置为 YES,Launch Services 将应用程序作为代理应用程序运行。 Agent apps do not appear in the Dock or in the Force Quit window. Although they typically run as background apps, they can come to the foreground to present a user interface if desired.代理应用程序不会出现在 Dock 或强制退出 window 中。虽然它们通常作为后台应用程序运行,但如果需要,它们可以出现在前台以呈现用户界面。 A click on a window belonging to an agent app brings that app forward to handle events.单击属于代理应用程序的 window 会使该应用程序前进以处理事件。

The Dock and loginwindow are two apps that run as agent apps. Dock 和 loginwindow 是两个作为代理应用程序运行的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM