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

发布于 2024-09-12 17:48:00 字数 453 浏览 2 评论 0原文

编辑:这是一个很好的现成菜单栏应用程序 此处github 源),作者:答案


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

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

在此处输入图像描述

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

EDIT: This is a nice ready-made menubar application here (github source) by this answer.


I was wondering how to make a menubar application, what are the requirements for that to do so?

I saw a simple application for the menubar was to open links using your browser, I want to create something similar to that.

enter image description here

This is the application I like to make similar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风苍溪 2024-09-19 17:48:00

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

NSStatusItem is what you are looking for. Also add LSUIElement with string value of 1 to your Info.plist to hide it from Dock.

不即不离 2024-09-19 17:48:00

我发现 Codebox 的弹出窗口是一个很好的起点。 在 Github 上进行分叉的时机已经成熟。

在此处输入图像描述

虽然效果很好,但他们确实在网站上注明...

PS 在 Lion 中,Apple 为弹出窗口添加了一个新类,就像在 iOS 中一样。
所以,OS X 10.7发布后,你最好还是依赖原生
可能的话可可课程。在其他情况下,Popup 项目
应该还是可以用的。

I've found Codebox's Popup to be a great starting point. It is ripe for forking on Github.

enter image description here

Though it works nicely, they do note on their site...

P. S. In Lion, Apple is adding a new class for popovers like in iOS.
So, after OS X 10.7 is released, you would better to rely on native
Cocoa classes where it is possible. In other cases, the Popup project
should still be usable.

乖乖哒 2024-09-19 17:48:00

BitBarGitHub 可以“将任何内容放入 Mac OS X 菜单栏中”。

它运行 shell 或其他可执行脚本(它称为 插件 - 请参阅插件存储库中的许多示例 )并在菜单栏中显示结果。您可以编写自己的插件并只需将其添加到“插件文件夹”即可运行。除了显示信息之外,它还可以从您定义的插件菜单交互地运行预定义的 bash 脚本。

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

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

在此处输入图像描述

BitBar is an application on GitHub that can "Put anything in your Mac OS X menu bar".

It runs shell or other executable scripts (which it calls Plugins - see the many examples in the plugins repo) and displays the results in the menu bar. You can write your own plugin and have it run simply by adding it to the 'Plugins folder'. As well as displaying information, it can also run pre-defined bash scripts interactively from the plugin menus you define.

Since I first posted this answer it's popularity has exploded (52 contributors currently) and there is now even a distributable version with which you can package your own plugins.

A very simple (non-interactive) example to show live Bitcoin price:

enter image description here

淡淡の花香 2024-09-19 17:48:00

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

https://github.com/taichino/PopupTest

As Apple added NSStatusBarButton property to NSStatusItem in Yosemite, we can implement menubar app a lot simpler. I just created a sample project on github.

https://github.com/taichino/PopupTest

关于从前 2024-09-19 17:48:00

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];

FlyCut is another nice open source application that does this. (MIT licensed.) Very handy too, I use it several times a day.

Here's some code that seems like it may be relevant:

    // 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];
孤凫 2024-09-19 17:48:00

Mail Notifr 是另一个开源菜单栏应用程序。它对我帮助很大,特别是当我需要弄清楚如何实现登录时打开时。也可在 App Store 上获取。

Mail Notifr is another open source Menubar app. It helped me a bunch, especially when I needed to figure out how to implement the open on login. Also available on the App Store.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文