Use ASOC to make an Objc script do an action?

How could you use applescript to call forth an action from an objective c script in the same application.

I have the class file referenced as shown below but what do i type in to cause the action to start.

property artworkcontrol : class “ArtworkController” of current application
artworkcontrol’s (code to call action in Objc)

what goes in the “()” ?

I think you can do this by just using the ASOC adjusted name for your C method. I created an Objective C method in a new class called AttachedAlert that was defined as this:

  • (void)bringupSheetOnWindow: (NSWindow*)window WithMessage: (NSString*)messageText andInfoText:(NSString*) infoText

And I call it from the applescript with:

property attachedAlert: class “AttachedAlert”
attachedAlert’s bringupSheetOnWindow_WithMessage_andInfoText_(myWindow, “message”, “info”)

So, it’s just like calling any other Cocoa method.

Im having trouble getting applescript to call an action in ObjectiveC that goes:

-(void)displaymenubaritem {

statusItem = [[[NSStatusBar systemStatusBar] 
			   statusItemWithLength:NSVariableStatusItemLength]
			  retain];
[statusItem setHighlightMode:YES];
[statusItem setEnabled:YES];
[statusItem setToolTip:@"InstaPlay"];
[statusItem setMenu:theMenu];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"menuiconBLACK" ofType:@"png"];
menuIcon= [[NSImage alloc] initWithContentsOfFile:path];
//[statusItem setTitle:[NSString stringWithString:@"test"]]; 
[statusItem setImage];
[menuIcon release];	

}

and in applescript I have tried all of the following:
property menubarcontroller : class “Menulet”

menubarcontroller’s displaymenubaritem
menubarcontroller’s displaymenubaritem_
menubarcontroller’s displaymenubaritem_()
menubarcontroller’s displaymenubaritem_(sender)

None of the above worked is the OBJC action incorrectly written? It originally was an awakefromnib but instead I wanted it to happen in OBJC when the applescript told it to do so. So i changed it to the (void)displaymenubaritem

Any ideas to get this to work?

What is the error in the console?

The correct form is menubarcontroller’s displaymenubaritem(), although you can probably drop the parens. But that’s not your problem – it looks like you’re trying to call an instance method on a class rather than an instance.

the console states:

2010-04-27 21:17:50.075 InstaPlay 11[14665:a0f] +[Menulet displaymenubaritem]: unrecognized selector sent to class 0x100002220
2010-04-27 21:17:50.077 InstaPlay 11[14665:a0f] *** -[Others changeappstate:]: +[Menulet displaymenubaritem]: unrecognized selector sent to class 0x100002220 (error -10000)

how exactly would i rewrite the:
-(void)displaymenubaritem {
}

Theoretically, you just change the leading - to a +. But it might not be that simple – if the handler uses properties of the Menulet class, it won’t run as a class method anyhow.

So you may be better to make an instance of the class, and call the method on that. You make the instance in IB by dragging in an NSObject blue cube, then changing its class to Menulet. Then change:

property menubarcontroller : class "Menulet"

to:

property menubarcontroller : missing value

Finally, in IB connect the Menulet instance to the property menubarcontroller.