我想选择隐藏Dock图标并显示NSStatusItem。我可以创建StatusItem,但是我不知道如何从Dock中删除图标。:-/
有什么想法吗?
发布于 2009-03-07 00:09:23
我想您正在查找Info.plist中的LSUIElement
LSUIElement (字符串)。如果此注册表项设置为“1”,则启动服务将应用程序作为代理应用程序运行。代理应用程序不会出现在Dock或Force Quit窗口中。尽管它们通常作为后台应用程序运行,但如果需要,它们也可以来到前台来呈现用户界面。
查看有关打开/关闭它的简短讨论here
发布于 2012-02-10 08:01:56
您可以使用所谓的激活策略:
Objective-C
// The application is an ordinary app that appears in the Dock and may
// have a user interface.
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
// The application does not appear in the Dock and does not have a menu
// bar, but it may be activated programmatically or by clicking on one
// of its windows.
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
// The application does not appear in the Dock and may not create
// windows or be activated.
[NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];Swift 4
// The application is an ordinary app that appears in the Dock and may
// have a user interface.
NSApp.setActivationPolicy(.regular)
// The application does not appear in the Dock and does not have a menu
// bar, but it may be activated programmatically or by clicking on one
// of its windows.
NSApp.setActivationPolicy(.accessory)
// The application does not appear in the Dock and may not create
// windows or be activated.
NSApp.setActivationPolicy(.prohibited)这应该会隐藏停靠图标。
另请参阅
启发这个问题的
发布于 2011-01-14 08:11:15
要做到这一点,同时遵守苹果的指导方针,不修改应用程序捆绑包,并保证Mac App Store应用程序/(Lion应用程序?)不会因为修改info.plist而破坏它们的签名,您可以默认将LSUIElement设置为1,然后在应用程序启动时这样做:
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);以显示其停靠图标,或者如果用户选择不想要该图标,则跳过此操作。
只有一个副作用,应用程序的菜单直到失去并重新获得焦点时才会显示出来。
来源:Making a Checkbox Toggle The Dock Icon On and Off
就我个人而言,我不喜欢设置任何Info.plist选项,而是根据用户设置使用TransformProcessType(&psn, kProcessTransformToForegroundApplication)或TransformProcessType(&psn, kProcessTransformToUIElementApplication)。
https://stackoverflow.com/questions/620841
复制相似问题