我正在寻找编写 Mac OS X Finder 插件的指南或示例代码?它想知道如何做一些简单的 Action :
我找到了以下两个资源:
COM
API。我很想查看 SCPlugin
代码,但希望找到更容易消化的示例。
最佳答案
Finder Icon Overlay示例项目代表了以下答案的一个小而非常基本但实际可行的示例。
https://github.com/lesnie/Finder-Icon-Overlay
我知道这已经很老了,但有些人可能仍然对主题感兴趣(?)
这是我在 Leopard (10.6) 下所做的。首先需要适当的 Finder 标题。使用类转储工具来获取它。然后将您的代码编写为 SIMBL 插件(请参阅文档如何操作),混合一些方法。例如在 ListView 中的图标上绘制一些东西,drawIconWithFrame: TIconAndTextCell 方法的方法必须被覆盖。
这是方法调配的代码:
+ (void) Plugin_load
{
Method old, new;
Class self_class = [self class];
Class finder_class = [objc_getClass("TIconAndTextCell") class];
class_addMethod(finder_class, @selector(FT_drawIconWithFrame:),
class_getMethodImplementation(self_class, @selector(FT_drawIconWithFrame:)),"v@:{CGRect={CGPoint=dd}{CGSize=dd}}");
old = class_getInstanceMethod(finder_class, @selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, @selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);
}
我正在用我的方法“FT_drawIconWithFrame:”覆盖“drawIconWithFrame:”方法。以下是此方法的示例实现。
- (void) FT_drawIconWithFrame:(struct CGRect)arg1
{
[self FT_drawIconWithFrame:arg1];
if ([self respondsToSelector:@selector(node)]) {
if ([[[[NSClassFromString(@"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent] hasPrefix:@"A"])
[myPrettyIconOverlayImage drawInRect:NSMakeRect(arg1.origin.x, arg1.origin.y, arg1.size.height, arg1.size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
}
本质上,它会在文件名以字母“A”开头的文件的每个图标上绘制“myPrettyIconOverlayImage”。这个逻辑由你决定。
注意这一行: [self FT_drawIconWithFrame:arg1];
这是如何调用 'super' 以获得正常的图标和名称等。我知道,看起来很奇怪,像循环,但实际上并非如此。然后封装到 SIMBL 插件中,安装 SIMBL 并...运行。
由于 Lion 的变化,一些工作必须从头开始(创建新的“Finder.h”文件,其中包含所需的所有声明,找到合适的类和方法来覆盖),但这种技术仍然有效。
黑客愉快!
https://stackoverflow.com/questions/1294335/