I was able to create a small Menubar app using ApplescriptObjC, and it works just fine, the menu displays and I am also able to use different icons. Now I have been trying to differentiate between Right and Left clicks, in order to trigger different actions depending on the pressed button. What I would like to do is display the menu when the right mouse button is pressed, and when the left one is pressed, trigger a handler like:
on leftButtonPressed_(sender)
display dialog "Left Button Pressed!"
end leftButtonPressed_
Eventually it will be substituted by something more complex. What I have done until now is create a custom class with all the ObjC code required in order to make the Menubar app work. here it is:
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
My Problem now is that I have no idea how to actually intercept the right and left mouse click, and how to bind it to a applescript handler. Can anyone help me???
Thanks in advance!