如何为 Mac 创建菜单栏应用程序
编辑:这是一个很好的现成菜单栏应用程序 此处(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.
This is the application I like to make similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
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.
我发现 Codebox 的弹出窗口是一个很好的起点。 在 Github 上进行分叉的时机已经成熟。
虽然效果很好,但他们确实在网站上注明...
I've found Codebox's Popup to be a great starting point. It is ripe for forking on Github.
Though it works nicely, they do note on their site...
BitBar 是 GitHub 可以“将任何内容放入 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:
由于 Apple 在 Yosemite 中向
NSStatusItem
添加了NSStatusBarButton
属性,我们可以更简单地实现菜单栏应用程序。我刚刚在 github 上创建了一个示例项目。https://github.com/taichino/PopupTest
As Apple added
NSStatusBarButton
property toNSStatusItem
in Yosemite, we can implement menubar app a lot simpler. I just created a sample project on github.https://github.com/taichino/PopupTest
FlyCut 是另一个很好的开源应用程序,可以做到这一点。 (麻省理工学院许可。)也非常方便,我每天使用它几次。
下面是一些看起来可能相关的代码:
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:
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.