简体   繁体   English

Mac OS X状态栏应用程序-从Cmd / Alt菜单隐藏它吗?

[英]Mac OS X Status Bar Application - Hiding it from Cmd/Alt menu?

I'm trying to whip up a simple little Status Bar Application in Obj-C/Cocoa. 我正在尝试在Obj-C / Cocoa中开发一个简单的小状态栏应用程序。

So I have done it pragmatically - declaring an NSStatusItem, adding it to the NSStatusBar and then giving it a NSMenu object. 因此,我务实地做到了这一点-声明一个NSStatusItem,将其添加到NSStatusBar,然后给它一个NSMenu对象。 A bit like this... 有点像这样...

NSStatusBar *bar = [NSStatusBar systemStatusBar];

theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];

[theItem setTitle: NSLocalizedString(@"Tablet",@"")];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];

(Example taken from "Status Bar Programming Topics", Apple Documentation) (示例摘自Apple文档的“状态栏编程主题”)

Now ideally, I'd like this application to run and not be accessible from the CMD/ALT window changing "menu" (for lack of a better word), I've seen applications do it before and would like that really. 现在,理想情况下,我希望该应用程序能够运行,并且不能从CMD / ALT窗口更改“菜单”(因为缺少更好的词)进行访问(我以前见过,并且确实希望这样做)。 The idea is I just want it to be accessible from every window, whilst not having its own NSMenu on the status bar, and whilst not being able to have it as the active application ( - so its not able to take over the whole Status Bar, and its not able to be seen through CMD/ALT) 我的想法是我只希望可以从每个窗口访问它,而在状态栏上没有它自己的NSMenu,并且不能将其作为活动应用程序使用(-因此,它不能接管整个状态栏。 ,并且无法通过CMD / ALT看到)

Additionally, I was wondering if the StatusBarItem supports the ability to drag-n-drop an item onto it? 另外,我想知道StatusBarItem是否支持将项目拖放到其上的功能? I'm not sure if thats a limitation of the NSStatusBar though. 我不确定那是否是NSStatusBar的限制。

I've read up on deamons and agents, but that seems far too low level/over kill for such a simplistic app! 我已经阅读了有关恶作剧和特工的内容,但是对于这样一个简单的应用程序来说,这似乎太低了!

Cheers in advance! 提前加油!

Put the LSUIElement key in your app's info.plist. LSUIElement键放在应用程序的info.plist中。 To do drag and drop, you set the status item's view to whatever view should receive the drop and it works normally from there on out. 要进行拖放,您可以将状态项的视图设置为应该接收该拖放的任何视图,并且此后可以正常工作。

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

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