0

我想制作一个非常基本的 SIMBL 插件 - 只需在 Safari 中添加一个新菜单。这是我尝试过的:我将此添加到我的 plist 中:

<key>NSPrincipalClass</key>
<string>MySamplePlugin</string>
<key>SIMBLTargetApplications</key>
<array>
    <dict>
        <key>BundleIdentifier</key>
        <string>com.apple.Safari</string>
        <key>MaxBundleVersion</key>
        <string>*</string>
        <key>MinBundleVersion</key>
        <string>*</string>
    </dict>
</array>

然后我创建了 MySamplePlugin 类和 Menu.xib。(所有连接都已建立,这不会是错误)我的 .h

-(IBAction)clickAbout:(id)sender;
@property (assign) IBOutlet NSMenu *topMenu;

和我的 .main 文件

- (id) init {
self = [super init];
if (! self)
    return nil;

[NSBundle loadNibNamed: @"Menu.xib" owner: self];
return self;
}

- (IBAction) clickAbout: (id) sender {
 NSLog(@"do some stuff here");
}



+ (void) load
{
MySamplePlugin* plugin = [MySamplePlugin sharedInstance];
NSMenuItem* item;

item = [[NSMenuItem alloc] init];
[item setSubmenu: [plugin topMenu]];

[[plugin topMenu] setTitle: @"George"];

[[NSApp mainMenu] addItem: item];

NSLog(@"MySamplePlugin installed");
}

+ (MySamplePlugin*) sharedInstance
{
static MySamplePlugin* plugin = nil;

if (plugin == nil)
    plugin = [[MySamplePlugin alloc] init];

return plugin;
}

知道为什么我的插件不工作吗?它在没有警告的情况下构建,我将其复制到 ~/Library/Application Support/SIMBL/Plugins/

这是我的 console.app 输出:http ://cl.ly/LsH9

4

1 回答 1

0

没关系,我通过这个小小的代码修改得到了它:

 NSMenu* mainMenu = [NSApp mainMenu];

NSMenu* debugMenu = [[NSMenu alloc] initWithTitle:@"Menu"];
NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:@"Item" action:nil keyEquivalent:@""];

[newItem setSubmenu:debugMenu];
[mainMenu addItem:newItem];
[debugMenu addItemWithTitle:@"Run Unit Tests" action:nil keyEquivalent:@""];
于 2012-12-31T15:40:29.547 回答