Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling multiple arguments from objective-c to applescript-objc

I have a applescript-objc script with a method as follows :-

on say_(phrase, userName)
    set whatToSay to "\"" & phrase & " " & userName & "\""
    say whatToSay
end say_

And i want to call this method from objective-c but cant seem to figure out how to call methods with multiple arguments, i have no problem calling methods with only one argument as follows :-

@interface NSObject (ASHandlers)
- (void)say:(NSString *)phrase;
@end

@implementation AppDelegate

@synthesize window, sayTextField;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
   scriptFile = NSClassFromString(@"Test");
   if ( !scriptFile ){
      // Handle errors here
   return;
   }
}

- (IBAction)say:(id)sender{
   NSString *phrase = [sayTextField stringValue];
   [scriptFile say:phrase];
}

please can someone help.

Regards, Andy.

like image 487
Andy Avatar asked Dec 14 '25 16:12

Andy


1 Answers

For starters, IBActions must have a signature of:

-(void)action;
-(void)actionWithSender:(id)sender;
-(void)actionWithSender:(id)sender event:(UIEvent*)event;

So you can't have an IBAction with multiple arguments if that's what you were looking for.

However, to answer your question, to have a method with multiple arguments, in Objective-C, it would look like this:

- say:(NSString *)textToSay withUserName:(NSString *)userName {
   ...
}

In AppleScriptObjC, you move all of your Objective-C method parameters to the beginning of the method name, replace the colons with underscores, and put your arguments in the parentheses.

on say_withUserName_(textToSay, userName)
    ...
end say_withUserName_ 
like image 113
snickle Avatar answered Dec 18 '25 02:12

snickle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!