macos 向 Finder 工具栏添加按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8380562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding buttons to Finder toolbar?
提问by cannyboy
Dropbox has the option of adding a button to the Finder toolbar. It even appears in the 'Customize Toolbar...' window. ? I can't find any documentation on how this sort of thing is done.... Does anyone know how to do this, or can anyone point me towards some documentation or sample code?
Dropbox 可以选择向 Finder 工具栏添加按钮。它甚至出现在“自定义工具栏...”窗口中。? 我找不到有关如何完成此类事情的任何文档.... 有谁知道如何做到这一点,或者任何人都可以指点我一些文档或示例代码?
EDIT ONE:
编辑一:
I guess a start would be finding the location of the existing icons, and any related code.
我想首先要找到现有图标的位置,以及任何相关的代码。
I noticed that Dropbox has files in Library/DropboxHelperTools/Dropbox_u501 called mach_inject_bundle_stub.bundle and FinderLoadBundle which might be doing the magic. Dropbox is also putting the 'tick' badge on Finder icons. This code might be involved: github.com/rentzsch/mach_star
我注意到 Dropbox 在 Library/DropboxHelperTools/Dropbox_u501 中有名为 mach_inject_bundle_stub.bundle 和 FinderLoadBundle 的文件,它们可能正在发挥作用。Dropbox 还在 Finder 图标上添加了“勾号”标志。此代码可能涉及:github.com/rentzsch/mach_star
EDIT TWO: A Dropbox talk by Rian Hunter about the process is here, at around 15:30 http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-how-dropbox-did-it-and-how-python-helped-4896698
编辑二:Rian Hunter 关于这个过程的 Dropbox 演讲在这里,大约 15:30 http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-how-dropbox-did- it-and-how-python-helped-4896698
Looking in the DropboxBundle file in the Dropbox_u501 shows the icons and some compiled code. The code suggests that Rian Hunter is the author: http://twitter.com/timeserena
查看 Dropbox_u501 中的 DropboxBundle 文件会显示图标和一些编译代码。代码表明 Rian Hunter 是作者:http: //twitter.com/timeserena
Rian has his own version of the Mach Star code on his github - https://github.com/rianhunter/mach_star- tho it seems much older
Rian 在他的 github 上有他自己版本的 Mach Star 代码 - https://github.com/rianhunter/mach_star- 但它似乎更老
EDIT THREE
编辑三
There was a 'Code Injection Workshop' at Stanford a few weeks ago - http://stanfordacm.com/past/- hosted by Rian. If anyone has notes from this please let me know!
几周前,斯坦福大学举办了一场“代码注入研讨会” - http://stanfordacm.com/past/- 由 Rian 主持。如果有人有这方面的笔记,请告诉我!
采纳答案by duskwuff -inactive-
Dropbox was using undocumented magic. There's no officially supported way to do this; the closest you can get without reverse engineering is Services.
Dropbox 使用了无证魔法。没有官方支持的方法来做到这一点;在没有逆向工程的情况下,您可以获得的最接近的是Services。
(Update: As of macOS 10.11, what Dropbox was doing is no longer possible at all. System Integrity Protection now prevents code from being injected into system processes, such as the Finder.)
(更新:从 macOS 10.11 开始,Dropbox 所做的一切不再可能。系统完整性保护现在可以防止将代码注入系统进程,例如 Finder。)
回答by Parag Bafna
You can use Finder Sync app extension(Starting in OS X v10.10).
您可以使用 Finder Sync应用扩展(从 OS X v10.10 开始)。
A Finder Sync extension can:
- Add, remove, and update badges and labels on items in a monitored folder.
- Display a contextual menu when the user Control-clicks an item inside a monitored folder.
- Add a custom button to the Finder's toolbar.
Finder 同步扩展可以:
- 添加、删除和更新受监控文件夹中项目的徽章和标签。
- 当用户按住 Control 键单击受监控文件夹内的项目时显示上下文菜单。
- 将自定义按钮添加到 Finder 的工具栏。
回答by shon
Rian's talk at PyCon 2011 (on blip.tv) does not explain anything more than "We reverse-engineered Finder." Although the mach_star stuff is valuable, it still doesn't explain how to get a sidebar icon working. And the Stanford 'Code Injection Workshop' has not posted any content about this method.
Rian 在 PyCon 2011 上的演讲(在 blip.tv 上)除了“我们对 Finder 进行了逆向工程”之外没有解释任何其他内容。虽然 mach_star 的东西很有价值,但它仍然没有解释如何让侧边栏图标工作。而斯坦福的“代码注入研讨会”也没有发布任何关于这种方法的内容。
I've nm'd and class-dump'd both bundles that Dropbox installs for each user under /Library/DropboxHelperTools, and the output provides good insight. If I get back to it, I'll finish my research and post it. Odds are, it won't be for some time, so here's hoping this nudge helps someone else.
我已经在 /Library/DropboxHelperTools 下对 Dropbox 为每个用户安装的两个包进行了 nm'd 和 class-dump,输出提供了很好的洞察力。如果我回到它,我会完成我的研究并发布它。很可能,它不会在一段时间内出现,所以这里希望这种轻推能帮助其他人。
回答by xyz
An easy intermediate answer that may be adequate for some people is to simply create icons that look like buttons.
对于某些人来说,一个简单的中间答案可能就足够了,就是简单地创建看起来像按钮的图标。
e.g. I created 'new text file here' and 'new terminal here icons' for my Finder:
例如,我为 Finder 创建了“此处的新文本文件”和“此处的新终端图标”:
The method can be found here.
该方法可以在这里找到。
The disadvantage is that they must be square and do not have animations/menus or show up in 'customize toolbar' etc.
缺点是它们必须是方形的并且没有动画/菜单或显示在“自定义工具栏”等中。