我想制作一个非常基本的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
答案 0 :(得分: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:@""];