如何为Mac创建菜单栏应用程序

时间:2010-08-04 21:29:16

标签: macos cocoa menubar

编辑:这是一个很好的现成的菜单栏应用heregithub sourceanswer


我想知道如何制作菜单栏应用程序,这样做的要求是什么?

我看到一个简单的菜单栏应用程序是使用您的浏览器打开链接,我想创建类似的东西。

enter image description here

这是我喜欢的类似的应用程序。

6 个答案:

答案 0 :(得分:132)

NSStatusItem正是您要找的。还要将字符串值为1的LSUIElement添加到Info.plist中,以将其从Dock中隐藏。

答案 1 :(得分:66)

我发现Codebox's Popup是一个很好的起点。 forking on Github.

已经成熟

enter image description here

虽然效果很好,但他们会在自己的网站上注明......

  

P上。 S.在Lion中,Apple正在为iOS中的popovers添加一个新类。   因此,在OS X 10.7发布之后,您最好依赖原生   可可类在哪里可行。在其他情况下,Popup项目   应该仍然有用。

答案 2 :(得分:12)

BitBarGitHub上的一个应用程序,可以“将任何内容放入Mac OS X菜单栏中”。

它运行shell或其他可执行脚本(它调用Plugins - see the many examples in the plugins repo)并在菜单栏中显示结果。您可以编写自己的插件,只需将其添加到“插件文件夹”即可运行。除了显示信息外,它还可以从您定义的插件菜单中以交互方式运行预定义的bash脚本。

自从我第一次发布此答案以来,它的受欢迎程度为exploded(目前有52位贡献者),现在甚至还有一个可分发的版本,您可以使用它来打包自己的插件。

显示实时比特币价格的非常简单(非交互式)示例:

enter image description here

答案 3 :(得分:10)

由于Apple在Yosemite中将NSStatusBarButton属性添加到NSStatusItem,我们可以更简单地实现菜单栏应用。我刚刚在github上创建了一个示例项目。

https://github.com/taichino/PopupTest

答案 4 :(得分:2)

FlyCut是另一个很好的开源应用程序。 (麻省理工学院许可。)非常方便,我每天使用它几次。

以下是一些似乎可能相关的代码:

    // Flycut/AppController.h
    IBOutlet NSMenu *jcMenu;

    // Flycut/AppController.m
    statusItem = [[[NSStatusBar systemStatusBar]
            statusItemWithLength:NSVariableStatusItemLength] retain];
    [statusItem setHighlightMode:YES];

    if ( [[DBUserDefaults standardUserDefaults] integerForKey:@"menuIcon"] == 1 ) {
        [statusItem setTitle:[NSString stringWithFormat:@"%C",0x2704]]; 
    } else if ( [[DBUserDefaults standardUserDefaults] integerForKey:@"menuIcon"] == 2 ) {
        [statusItem setTitle:[NSString stringWithFormat:@"%C",0x2702]]; 
    } else {
        [statusItem setImage:[NSImage imageNamed:@"com.generalarcade.flycut.16.png"]];
    }
    [statusItem setMenu:jcMenu];
    [statusItem setEnabled:YES];

答案 5 :(得分:0)

Mail Notifr是另一个开源菜单栏应用。它帮了我一堆,特别是当我需要弄清楚如何在登录时实现open。也可在App Store上找到。

相关问题