1

我能够使用 ApplescriptObjC 创建一个小的菜单栏应用程序,它工作得很好,菜单显示,我还可以使用不同的图标。现在我一直在尝试区分右击和左击,以便根据按下的按钮触发不同的操作。我想做的是在按下鼠标右键时显示​​菜单,当按下鼠标左键时,触发如下处理程序:

on leftButtonPressed_(sender)
    display dialog "Left Button Pressed!"
end leftButtonPressed_

最终它将被更复杂的东西所取代。到目前为止,我所做的是创建一个自定义类,其中包含使 Menubar 应用程序正常工作所需的所有 ObjC 代码。这里是:

MenuBarAppAppDelegate.h:

#import <Cocoa/Cocoa.h>

@interface MenuBarAppAppDelegate : NSObject {
     NSMenuItem *MenuItem;
     IBOutlet NSMenu *statusMenu;

     NSStatusItem *statusItem;
     NSImage *menuIcon;
     NSImage *menuIconActive;
}
@end

MenuBarAppAppDelegate.m

#import "MenuBarAppAppDelegate.h"



@implementation MenuBarAppAppDelegate
-(void)dealloc
{
    [menuIcon release];
    [menuIconActive release];
    //[statusItem release];
    [super dealloc];
}

- (void)awakeFromNib
{
    statusItem = [[[NSStatusBar systemStatusBar]
                   statusItemWithLength:NSVariableStatusItemLength]
                  retain];

    NSBundle *bundle = [NSBundle bundleForClass:[self class]];

    menuIcon= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Icon1a" ofType:@"png"]];

    menuIconActive= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Icon2a" ofType:@"png"]];

    [statusItem setImage:menuIcon];
    [statusItem setTitle:@""];
    [statusItem setHighlightMode:YES];
    [statusItem setEnabled:YES];
    [statusItem setToolTip:@"Togglr"];
    [statusItem setMenu:statusMenu];


}






-(void)actMenuIcon{
    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    menuIcon= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"AppleLogoFullBlack" ofType:@"png"]];
    menuIconActive= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"AppleLogoFullWhite" ofType:@"png"]];



    [statusItem setImage:menuIcon];
    [statusItem setAlternateImage:menuIconActive];
    [statusItem setHighlightMode:YES];
}
-(void)desMenuIcon{

    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    menuIcon= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"AppleLogoEmptyBlack" ofType:@"png"]];
    menuIconActive= [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"AppleLogoEmptyWhite" ofType:@"png"]];

    [statusItem setImage:menuIcon];
    [statusItem setAlternateImage:menuIconActive];
    [statusItem setHighlightMode:YES];
}

@end

我现在的问题是我不知道如何实际拦截鼠标右键和左键单击,以及如何将其绑定到 applescript 处理程序。谁能帮我???

提前致谢!

4

0 回答 0