简体   繁体   English

向Finder工具栏添加按钮?

[英]Adding buttons to Finder toolbar?

Dropbox has the option of adding a button to the Finder toolbar. Dropbox可以选择向Finder工具栏添加按钮。 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? 我找不到任何关于如何完成此类事情的文档....有谁知道如何做到这一点,或者任何人都可以指向我一些文档或示例代码?

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在Library / DropboxHelperTools / Dropbox_u501中有一些名为mach_inject_bundle_stub.bundle和FinderLoadBundle的文件可能正在发挥作用。 Dropbox is also putting the 'tick' badge on Finder icons. Dropbox还在Finder图标上添加了“tick”徽章。 This code might be involved: github.com/rentzsch/mach_star 可能涉及此代码: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-它和如何的Python-帮助-4896698

Looking in the DropboxBundle file in the Dropbox_u501 shows the icons and some compiled code. 查看Dropbox_u501中的DropboxBundle文件显示了图标和一些已编译的代码。 The code suggests that Rian Hunter is the author: http://twitter.com/timeserena 代码表明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. 几周前斯坦福大学举办了“代码注射研讨会” - http://stanfordacm.com/past/--由Rian主持。 If anyone has notes from this please let me know! 如果有人有这方面的说明,请告诉我!

You can use Finder Sync app extension (Starting in OS X v10.10). 您可以使用Finder Sync 应用程序扩展 (从OS X v10.10开始)。

A Finder Sync extension can: Finder Sync扩展程序可以:

  • 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. 当用户按住Control键单击受监视文件夹中的项目时,显示上下文菜单。
  • Add a custom button to the Finder's toolbar. 将自定义按钮添加到Finder的工具栏。

Dropbox was using undocumented magic. Dropbox使用的是无证魔法。 There's no officially supported way to do this; 没有官方支持的方法来做到这一点; the closest you can get without reverse engineering is 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。)

Rian's talk at PyCon 2011 (on blip.tv) does not explain anything more than "We reverse-engineered Finder." Rian在PyCon 2011上的演讲(关于blip.tv)并没有解释任何比“我们逆向工程Finder”更多的内容。 Although the mach_star stuff is valuable, it still doesn't explain how to get a sidebar icon working. 虽然mach_star的东西是有价值的,但它仍然没有解释如何使侧边栏图标工作。 And the Stanford 'Code Injection Workshop' has not posted any content about this method. 斯坦福大学的“Code Injection Workshop”尚未公布任何有关此方法的内容。

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. 我已经为/ Library / DropboxHelperTools下的每个用户安装了Dropbox安装的两个捆绑包,并且输出提供了很好的洞察力。 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. 可能性,它不会持续一段时间,所以这里希望这个推动帮助别人。

An easy intermediate answer that may be adequate for some people is to simply create icons that look like buttons. 对于某些人来说,一个简单的中间答案就是简单地创建看起来像按钮的图标。

eg I created 'new text file here' and 'new terminal here icons' for my Finder: 例如,我为我的Finder创建了“new text file here”和“new terminal here icons”:

在此输入图像描述

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. 缺点是它们必须是方形的,没有动画/菜单或显示在“自定义工具栏”等。

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

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