• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
problem passing a list to an AppleScript function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem passing a list to an AppleScript function


  • Subject: problem passing a list to an AppleScript function
  • From: Xavi Caballe Grebol <email@hidden>
  • Date: Thu, 1 Dec 2005 00:56:17 -0800

My Cocoa app calls an AppleScript function like this...

on test_function(a_list)
display dialog (length of a_list)
end test_function

To pass a list from Objective-C to the AppleScript function I've followed the code in...
http://www.cocoadev.com/index.pl?CallAppleScriptFunction

More concretely, here's how I set up the list parameter to send it to the AppleScript function...

NSAppleEventDescriptor *listDescriptor = [NSAppleEventDescriptor listDescriptor];
NSArray *listParamElements = [NSArray initWithObjects:@"element1", @"element2", nil];
int i;
for (i = 0; i < [listParamElements count]; ++i) {
// note that the array starts at index 1
[listDescriptor insertDescriptor:[NSAppleEventDescriptor descriptorWithString:[listParamElements objectAtIndex:i]]
atIndex:(i+1)];
}
// (...)
[event setParamDescriptor:listDescriptor forKeyword:keyDirectObject];


The problem is that the dialog displayed by test_function shows '5' instead of '2', so it seems that I'm doing something wrong.
(Mmm... I've just realized... maybe the problem is that I'm not really passing a list parameter, but a list of parameters? Anyway, if that's the case, how do I pass a parameter of type list?).

I've also tried to use Ken Ferry's KFAppleScript Handler Additions with a call like this...
[myTestScpt executeHandler:@"testScript"
withParameters:@"element1",@"element2", nil];

but then the dialog shown by AppleScript displays '9' (instead of '2').


I will be very grateful if someone could shed some light to my problem.

Thanks in advance,

xavi

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: problem passing a list to an AppleScript function
      • From: Xavi Caballe Grebol <email@hidden>
  • Prev by Date: Re: A simple question about nsthread
  • Next by Date: Re: problem passing a list to an AppleScript function
  • Previous by thread: Re: A simple question about nsthread
  • Next by thread: Re: problem passing a list to an AppleScript function
  • Index(es):
    • Date
    • Thread