为SIMBL插件生成“Finder.h”

时间:2012-03-18 19:15:39

标签: macos finder simbl

我正在尝试为Finder创建一个SIMBL插件,以便在某些文件上添加图标覆盖。

我有这段代码:

@implementation NSObject (FAIconOverlay)

- (void)FAIconOverlay_TIconAndTextCell_drawIconWithFrame:(struct CGRect)arg1
{
    [self FAIconOverlay_TIconAndTextCell_drawIconWithFrame:arg1];

    if (![self respondsToSelector:@selector(node)]) {
        return;
    }

    NSLog(@"%@", [[[NSClassFromString(@"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent]);

    // Draw the icon overlay
}

- (void)FAIconOverlay_TDesktopIcon_drawIconInContext:(struct CGContext *)arg1
{    
    [self FAIconOverlay_TDesktopIcon_drawIconInContext:arg1];
}

@end

我可以绘制图标叠加但是,当我尝试获取文件的路径时,我得到“使用未声明的标识符TNodeIconAndNameCell”。看这个链接< How to Write OS X Finder plugin>我看到生成Finder.h文件是必要的......

我的问题是:如何生成此文件?我尝试运行“class-dump -H Finder.app”,但我得到了更多的编译错误

非常感谢!

3 个答案:

答案 0 :(得分:4)

创建“ Finder.h ”:

sudo class-dump -H -o /output_directory/Path  /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder

答案 1 :(得分:1)

不应覆盖TIconAndTextCell的drawIconWithFrame:方法,而应覆盖TNodeIconAndNameCell的drawIconWithFrame:方法。

Class finder_class = [objc_getClass("TNodeIconAndNameCell") 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);

然后你可以这样做:

NSLog(@"%@", [[[NSClassFromString(@"FINode") nodeWithFENode:[self node]] fullPath] lastPathComponent]);

答案 2 :(得分:0)

解决方案不包括class-dump生成的所有头文件(现在如何生成此头文件检查@ jackjr300答案)。只有必要包括使用的标题并修复编译问题。